summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorhugbubby <hugbubby@protonmail.com>2018-07-04 11:21:43 -0700
committeriphydf <iphydf@users.noreply.github.com>2018-07-06 10:25:47 +0000
commit47a527509d1b9855fcc1bafe33177d7ed726faf8 (patch)
tree9872c612caefee2f532f27fe75887f3df381c81d /auto_tests
parent597f23bdd99e0962a6912231938543b42e6f43ab (diff)
lan_discovery_test and version_test cleanup
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.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/lan_discovery_test.c2
-rw-r--r--auto_tests/version_test.c30
2 files changed, 19 insertions, 13 deletions
diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c
index 237b51bb..3192fc28 100644
--- a/auto_tests/lan_discovery_test.c
+++ b/auto_tests/lan_discovery_test.c
@@ -10,7 +10,7 @@ int main(void)
10 Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); 10 Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
11 Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); 11 Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
12 12
13 printf("Waiting for LAN discovery"); 13 printf("Waiting for LAN discovery. This loop will attempt to run until successful.");
14 14
15 while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || 15 while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
16 tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { 16 tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) {
diff --git a/auto_tests/version_test.c b/auto_tests/version_test.c
index 5ceff595..7509397a 100644
--- a/auto_tests/version_test.c
+++ b/auto_tests/version_test.c
@@ -1,4 +1,5 @@
1#include "../toxcore/tox.h" 1#include "../toxcore/tox.h"
2#include "check_compat.h"
2 3
3#include <stdio.h> 4#include <stdio.h>
4#include <stdlib.h> 5#include <stdlib.h>
@@ -6,20 +7,16 @@
6#define check(major, minor, patch, expected) \ 7#define check(major, minor, patch, expected) \
7 do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \ 8 do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \
8 major, minor, patch, \ 9 major, minor, patch, \
9 TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch), expected,\ 10 TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch), expected)
10 &result)
11 11
12static void do_check(int lib_major, int lib_minor, int lib_patch, 12static void do_check(int lib_major, int lib_minor, int lib_patch,
13 int cli_major, int cli_minor, int cli_patch, 13 int cli_major, int cli_minor, int cli_patch,
14 bool actual, bool expected, 14 bool actual, bool expected)
15 int *result)
16{ 15{
17 if (actual != expected) { 16 ck_assert_msg(actual == expected,
18 printf("Client version %d.%d.%d is%s compatible with library version %d.%d.%d, but it should%s be\n", 17 "Client version %d.%d.%d is%s compatible with library version %d.%d.%d, but it should%s be\n",
19 cli_major, cli_minor, cli_patch, actual ? "" : " not", 18 cli_major, cli_minor, cli_patch, actual ? "" : " not",
20 lib_major, lib_minor, lib_patch, expected ? "" : " not"); 19 lib_major, lib_minor, lib_patch, expected ? "" : " not");
21 *result = EXIT_FAILURE;
22 }
23} 20}
24 21
25#undef TOX_VERSION_MAJOR 22#undef TOX_VERSION_MAJOR
@@ -28,11 +25,12 @@ static void do_check(int lib_major, int lib_minor, int lib_patch,
28 25
29int main(void) 26int main(void)
30{ 27{
31 int result = 0;
32#define TOX_VERSION_MAJOR 0 28#define TOX_VERSION_MAJOR 0
33#define TOX_VERSION_MINOR 0 29#define TOX_VERSION_MINOR 0
34#define TOX_VERSION_PATCH 4 30#define TOX_VERSION_PATCH 4
31 // Tox versions from 0.0.* are only compatible with themselves.
35 check(0, 0, 0, false); 32 check(0, 0, 0, false);
33 check(0, 0, 3, false);
36 check(0, 0, 4, true); 34 check(0, 0, 4, true);
37 check(0, 0, 5, false); 35 check(0, 0, 5, false);
38 check(1, 0, 4, false); 36 check(1, 0, 4, false);
@@ -43,6 +41,7 @@ int main(void)
43#define TOX_VERSION_MAJOR 0 41#define TOX_VERSION_MAJOR 0
44#define TOX_VERSION_MINOR 1 42#define TOX_VERSION_MINOR 1
45#define TOX_VERSION_PATCH 4 43#define TOX_VERSION_PATCH 4
44 // Tox versions from 0.1.* are only compatible with themselves or 0.1.<*
46 check(0, 0, 0, false); 45 check(0, 0, 0, false);
47 check(0, 0, 4, false); 46 check(0, 0, 4, false);
48 check(0, 0, 5, false); 47 check(0, 0, 5, false);
@@ -55,6 +54,7 @@ int main(void)
55 check(1, 0, 0, false); 54 check(1, 0, 0, false);
56 check(1, 0, 4, false); 55 check(1, 0, 4, false);
57 check(1, 0, 5, false); 56 check(1, 0, 5, false);
57 check(1, 1, 4, false);
58#undef TOX_VERSION_MAJOR 58#undef TOX_VERSION_MAJOR
59#undef TOX_VERSION_MINOR 59#undef TOX_VERSION_MINOR
60#undef TOX_VERSION_PATCH 60#undef TOX_VERSION_PATCH
@@ -62,11 +62,15 @@ int main(void)
62#define TOX_VERSION_MAJOR 1 62#define TOX_VERSION_MAJOR 1
63#define TOX_VERSION_MINOR 0 63#define TOX_VERSION_MINOR 0
64#define TOX_VERSION_PATCH 4 64#define TOX_VERSION_PATCH 4
65 // Beyond 0.*.* Tox is comfortable with any lower version within their major
66 check(0, 0, 4, false);
65 check(1, 0, 0, true); 67 check(1, 0, 0, true);
66 check(1, 0, 1, true); 68 check(1, 0, 1, true);
67 check(1, 0, 4, true); 69 check(1, 0, 4, true);
68 check(1, 0, 5, false); 70 check(1, 0, 5, false);
69 check(1, 1, 0, false); 71 check(1, 1, 0, false);
72 check(2, 0, 0, false);
73 check(2, 0, 4, false);
70#undef TOX_VERSION_MAJOR 74#undef TOX_VERSION_MAJOR
71#undef TOX_VERSION_MINOR 75#undef TOX_VERSION_MINOR
72#undef TOX_VERSION_PATCH 76#undef TOX_VERSION_PATCH
@@ -74,6 +78,7 @@ int main(void)
74#define TOX_VERSION_MAJOR 1 78#define TOX_VERSION_MAJOR 1
75#define TOX_VERSION_MINOR 1 79#define TOX_VERSION_MINOR 1
76#define TOX_VERSION_PATCH 4 80#define TOX_VERSION_PATCH 4
81 check(0, 0, 4, false);
77 check(1, 0, 0, true); 82 check(1, 0, 0, true);
78 check(1, 0, 4, true); 83 check(1, 0, 4, true);
79 check(1, 0, 5, true); 84 check(1, 0, 5, true);
@@ -85,9 +90,10 @@ int main(void)
85 check(1, 2, 4, false); 90 check(1, 2, 4, false);
86 check(1, 2, 5, false); 91 check(1, 2, 5, false);
87 check(2, 0, 0, false); 92 check(2, 0, 0, false);
93 check(2, 1, 4, false);
88#undef TOX_VERSION_MAJOR 94#undef TOX_VERSION_MAJOR
89#undef TOX_VERSION_MINOR 95#undef TOX_VERSION_MINOR
90#undef TOX_VERSION_PATCH 96#undef TOX_VERSION_PATCH
91 97
92 return result; 98 return 0;
93} 99}