Avoid redefining macros from different files.

This commit is contained in:
iphydf 2018-08-19 22:58:04 +00:00
parent 0e7cc197f4
commit 7aa57afeba
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
4 changed files with 37 additions and 32 deletions

View File

@ -6,16 +6,16 @@
#include <string.h>
#define SAVE_FILE "../auto_tests/data/save.tox"
#define LOADED_SAVE_FILE "../auto_tests/data/save.tox"
// Information from the save file
#define NAME "name"
#define NAME_SIZE strlen(NAME)
#define STATUS_MESSAGE "Hello World"
#define STATUS_MESSAGE_SIZE strlen(STATUS_MESSAGE)
#define NUM_FRIENDS 1
#define NOSPAM "4C762C7D"
#define TOX_ID "B70E97D41F69B7F4C42A5BC7BD7A76B95B8030BE1B7C0E9E6FC19FC4ABEB195B4C762C7D800B"
#define EXPECTED_NAME "name"
#define EXPECTED_NAME_SIZE strlen(EXPECTED_NAME)
#define EXPECTED_STATUS_MESSAGE "Hello World"
#define EXPECTED_STATUS_MESSAGE_SIZE strlen(EXPECTED_STATUS_MESSAGE)
#define EXPECTED_NUM_FRIENDS 1
#define EXPECTED_NOSPAM "4C762C7D"
#define EXPECTED_TOX_ID "B70E97D41F69B7F4C42A5BC7BD7A76B95B8030BE1B7C0E9E6FC19FC4ABEB195B4C762C7D800B"
static size_t get_file_size(const char *save_path)
{
@ -83,38 +83,41 @@ static void test_save_compatibility(const char *save_path)
free(save_data);
const size_t name_size = tox_self_get_name_size(tox);
ck_assert_msg(name_size == NAME_SIZE, "name sizes do not match expected %zu got %zu", NAME_SIZE, name_size);
ck_assert_msg(name_size == EXPECTED_NAME_SIZE, "name sizes do not match expected %zu got %zu", EXPECTED_NAME_SIZE,
name_size);
uint8_t name[TOX_MAX_NAME_LENGTH];
tox_self_get_name(tox, name);
ck_assert_msg(strncmp((const char *)name, NAME, name_size) == 0, "names do not match, expected %s got %s", NAME, name);
ck_assert_msg(strncmp((const char *)name, EXPECTED_NAME, name_size) == 0,
"names do not match, expected %s got %s", EXPECTED_NAME, name);
const size_t status_message_size = tox_self_get_status_message_size(tox);
ck_assert_msg(status_message_size == STATUS_MESSAGE_SIZE, "status message sizes do not match, expected %zu got %zu",
STATUS_MESSAGE_SIZE, status_message_size);
ck_assert_msg(status_message_size == EXPECTED_STATUS_MESSAGE_SIZE,
"status message sizes do not match, expected %zu got %zu", EXPECTED_STATUS_MESSAGE_SIZE, status_message_size);
uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
tox_self_get_status_message(tox, status_message);
ck_assert_msg(strncmp((const char *)status_message, STATUS_MESSAGE, status_message_size) == 0,
ck_assert_msg(strncmp((const char *)status_message, EXPECTED_STATUS_MESSAGE, status_message_size) == 0,
"status messages do not match, expected %s got %s",
STATUS_MESSAGE, status_message);
EXPECTED_STATUS_MESSAGE, status_message);
const size_t num_friends = tox_self_get_friend_list_size(tox);
ck_assert_msg(num_friends == NUM_FRIENDS, "number of friends do not match, expected %d got %zu", NUM_FRIENDS,
num_friends);
ck_assert_msg(num_friends == EXPECTED_NUM_FRIENDS,
"number of friends do not match, expected %d got %zu", EXPECTED_NUM_FRIENDS, num_friends);
const uint32_t nospam = tox_self_get_nospam(tox);
char nospam_str[(TOX_NOSPAM_SIZE * 2) + 1];
const size_t length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam);
nospam_str[length] = '\0';
ck_assert_msg(strcmp(nospam_str, NOSPAM) == 0, "nospam does not match, expected %s got %s", NOSPAM, nospam_str);
ck_assert_msg(strcmp(nospam_str, EXPECTED_NOSPAM) == 0,
"nospam does not match, expected %s got %s", EXPECTED_NOSPAM, nospam_str);
uint8_t tox_id[TOX_ADDRESS_SIZE];
char tox_id_str[TOX_ADDRESS_SIZE * 2];
tox_self_get_address(tox, tox_id);
to_hex(tox_id_str, tox_id, TOX_ADDRESS_SIZE);
ck_assert_msg(strncmp(tox_id_str, TOX_ID, TOX_ADDRESS_SIZE * 2) == 0, "tox ids do not match, expected %s got %s",
TOX_ID, tox_id_str);
ck_assert_msg(strncmp(tox_id_str, EXPECTED_TOX_ID, TOX_ADDRESS_SIZE * 2) == 0,
"tox ids do not match, expected %s got %s", EXPECTED_TOX_ID, tox_id_str);
tox_kill(tox);
}
@ -133,7 +136,7 @@ int main(int argc, char *argv[])
}
char save_path[4096];
snprintf(save_path, sizeof(save_path), "%s/%s", base_path, SAVE_FILE);
snprintf(save_path, sizeof(save_path), "%s/%s", base_path, LOADED_SAVE_FILE);
test_save_compatibility(save_path);

View File

@ -7,6 +7,7 @@ clang++ -o /dev/null amalgamation.cc \
$CPPFLAGS \
$LDFLAGS \
-std=c++11 \
-Werror \
-Weverything \
-Wno-c++98-compat-pedantic \
-Wno-c99-extensions \

View File

@ -7,16 +7,16 @@
#include "../../toxcore/ccompat.h"
#include "../../toxcore/tox.h"
#define SAVE_FILE "save.tox"
#define STATUS_MESSAGE "Hello World"
#define REQUEST_MESSAGE "Add me."
#define GENERATED_SAVE_FILE "save.tox"
#define GENERATED_STATUS_MESSAGE "Hello World"
#define GENERATED_REQUEST_MESSAGE "Add me."
#define BOOTSTRAP_IP "185.14.30.213"
#define BOOTSTRAP_ADDRESS "2555763C8C460495B14157D234DD56B86300A2395554BCAE4621AC345B8C1B1B"
#define UDP_PORT 443
#define BOOTSTRAP_UDP_PORT 443
static bool write_save(const uint8_t *data, size_t length)
{
FILE *fp = fopen(SAVE_FILE, "w");
FILE *fp = fopen(GENERATED_SAVE_FILE, "w");
if (!fp) {
return false;
@ -41,7 +41,7 @@ static bool bootstrap_tox(Tox *tox)
}
Tox_Err_Bootstrap err;
tox_bootstrap(tox, BOOTSTRAP_IP, UDP_PORT, key, &err);
tox_bootstrap(tox, BOOTSTRAP_IP, BOOTSTRAP_UDP_PORT, key, &err);
free(key);
if (err != TOX_ERR_BOOTSTRAP_OK) {
@ -80,7 +80,7 @@ static void print_information(Tox *tox)
printf("Tox ID: %.*s.\n", (int)TOX_ADDRESS_SIZE * 2, tox_id_str);
printf("Nospam: %s.\n", nospam_str);
printf("Name: %s.\n", name);
printf("Status message: %s.\n", STATUS_MESSAGE);
printf("Status message: %s.\n", GENERATED_STATUS_MESSAGE);
printf("Number of friends: %zu.\n", tox_self_get_friend_list_size(tox));
printf("----------------------------------\n");
}
@ -121,7 +121,7 @@ int main(int argc, char *argv[])
printf("Failed to set name. Error number %d\n", err);
}
tox_self_set_status_message(tox, (const uint8_t *)STATUS_MESSAGE, strlen(STATUS_MESSAGE), &err);
tox_self_set_status_message(tox, (const uint8_t *)GENERATED_STATUS_MESSAGE, strlen(GENERATED_STATUS_MESSAGE), &err);
if (err != TOX_ERR_SET_INFO_OK) {
printf("Failed to set status. Error number: %d\n", err);
@ -130,7 +130,8 @@ int main(int argc, char *argv[])
for (unsigned int i = 2; i < argc; i++) { //start at 2 because that is where the tox ids are
uint8_t *address = hex_string_to_bin(argv[i]);
Tox_Err_Friend_Add friend_err;
tox_friend_add(tox, address, (const uint8_t *)REQUEST_MESSAGE, strlen(REQUEST_MESSAGE), &friend_err);
tox_friend_add(tox, address, (const uint8_t *)GENERATED_REQUEST_MESSAGE, strlen(GENERATED_REQUEST_MESSAGE),
&friend_err);
free(address);
if (friend_err != TOX_ERR_FRIEND_ADD_OK) {
@ -158,7 +159,7 @@ int main(int argc, char *argv[])
return -1;
}
printf("Wrote tox save to %s\n", SAVE_FILE);
printf("Wrote tox save to %s\n", GENERATED_SAVE_FILE);
print_information(tox);

View File

@ -88,7 +88,7 @@ static const vpx_codec_iface_t *video_codec_encoder_interface(void)
#define VPX_MAX_ENCODER_THREADS 4
#define VPX_MAX_DECODER_THREADS 4
#define VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED 0
#define VIDEO_VP8_DECODER_POST_PROCESSING_ENABLED 0
static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist)
{
@ -210,7 +210,7 @@ VCSession *vc_new(const Mono_Time *mono_time, const Logger *log, ToxAV *av, uint
goto BASE_CLEANUP;
}
if (VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED == 1) {
if (VIDEO_VP8_DECODER_POST_PROCESSING_ENABLED == 1) {
vp8_postproc_cfg_t pp = {VP8_DEBLOCK, 1, 0};
vpx_codec_err_t cc_res = vpx_codec_control(vc->decoder, VP8_SET_POSTPROC, &pp);