mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
47a527509d
Removed a pointless declaration of a function in lan_discovery_test and cleaned up the one error message there. Did an entire restructuring of the version_test using macros that resulted in fewer lines of code but more thorough testing. Formatting of version_test.c back to old way, save comments and one change Missing space My greatest enemy Add `#include <cstdio>` for `std::printf`. Make tox.c unambiguously parseable. Rules: 1. Constants are uppercase names: THE_CONSTANT. 2. SUE[1] types start with an uppercase letter and have at least one lowercase letter in it: The_Type, THE_Type. 3. Function types end in "_cb": tox_friend_connection_cb. 4. Variable and function names are all lowercase: the_function. This makes it easier for humans reading the code to determine what an identifier means. I'm not convinced by the enum type name change, but I don't know a better rule. Currently, a lot of enum types are spelled like constants, which is confusing. [1] struct/union/enum Use run_auto_test.h test fixture for some auto-tests. Most of the auto-tests should use this fixture, but I've only done a few to set an example.
100 lines
2.8 KiB
C
100 lines
2.8 KiB
C
#include "../toxcore/tox.h"
|
|
#include "check_compat.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define check(major, minor, patch, expected) \
|
|
do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \
|
|
major, minor, patch, \
|
|
TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch), expected)
|
|
|
|
static void do_check(int lib_major, int lib_minor, int lib_patch,
|
|
int cli_major, int cli_minor, int cli_patch,
|
|
bool actual, bool expected)
|
|
{
|
|
ck_assert_msg(actual == expected,
|
|
"Client version %d.%d.%d is%s compatible with library version %d.%d.%d, but it should%s be\n",
|
|
cli_major, cli_minor, cli_patch, actual ? "" : " not",
|
|
lib_major, lib_minor, lib_patch, expected ? "" : " not");
|
|
}
|
|
|
|
#undef TOX_VERSION_MAJOR
|
|
#undef TOX_VERSION_MINOR
|
|
#undef TOX_VERSION_PATCH
|
|
|
|
int main(void)
|
|
{
|
|
#define TOX_VERSION_MAJOR 0
|
|
#define TOX_VERSION_MINOR 0
|
|
#define TOX_VERSION_PATCH 4
|
|
// Tox versions from 0.0.* are only compatible with themselves.
|
|
check(0, 0, 0, false);
|
|
check(0, 0, 3, false);
|
|
check(0, 0, 4, true);
|
|
check(0, 0, 5, false);
|
|
check(1, 0, 4, false);
|
|
#undef TOX_VERSION_MAJOR
|
|
#undef TOX_VERSION_MINOR
|
|
#undef TOX_VERSION_PATCH
|
|
|
|
#define TOX_VERSION_MAJOR 0
|
|
#define TOX_VERSION_MINOR 1
|
|
#define TOX_VERSION_PATCH 4
|
|
// Tox versions from 0.1.* are only compatible with themselves or 0.1.<*
|
|
check(0, 0, 0, false);
|
|
check(0, 0, 4, false);
|
|
check(0, 0, 5, false);
|
|
check(0, 1, 0, true);
|
|
check(0, 1, 4, true);
|
|
check(0, 1, 5, false);
|
|
check(0, 2, 0, false);
|
|
check(0, 2, 4, false);
|
|
check(0, 2, 5, false);
|
|
check(1, 0, 0, false);
|
|
check(1, 0, 4, false);
|
|
check(1, 0, 5, false);
|
|
check(1, 1, 4, false);
|
|
#undef TOX_VERSION_MAJOR
|
|
#undef TOX_VERSION_MINOR
|
|
#undef TOX_VERSION_PATCH
|
|
|
|
#define TOX_VERSION_MAJOR 1
|
|
#define TOX_VERSION_MINOR 0
|
|
#define TOX_VERSION_PATCH 4
|
|
// Beyond 0.*.* Tox is comfortable with any lower version within their major
|
|
check(0, 0, 4, false);
|
|
check(1, 0, 0, true);
|
|
check(1, 0, 1, true);
|
|
check(1, 0, 4, true);
|
|
check(1, 0, 5, false);
|
|
check(1, 1, 0, false);
|
|
check(2, 0, 0, false);
|
|
check(2, 0, 4, false);
|
|
#undef TOX_VERSION_MAJOR
|
|
#undef TOX_VERSION_MINOR
|
|
#undef TOX_VERSION_PATCH
|
|
|
|
#define TOX_VERSION_MAJOR 1
|
|
#define TOX_VERSION_MINOR 1
|
|
#define TOX_VERSION_PATCH 4
|
|
check(0, 0, 4, false);
|
|
check(1, 0, 0, true);
|
|
check(1, 0, 4, true);
|
|
check(1, 0, 5, true);
|
|
check(1, 1, 0, true);
|
|
check(1, 1, 1, true);
|
|
check(1, 1, 4, true);
|
|
check(1, 1, 5, false);
|
|
check(1, 2, 0, false);
|
|
check(1, 2, 4, false);
|
|
check(1, 2, 5, false);
|
|
check(2, 0, 0, false);
|
|
check(2, 1, 4, false);
|
|
#undef TOX_VERSION_MAJOR
|
|
#undef TOX_VERSION_MINOR
|
|
#undef TOX_VERSION_PATCH
|
|
|
|
return 0;
|
|
}
|