diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 16:10:48 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:54:37 +0100 |
commit | ad2656051697899e960694bb68ac104fcc5e92f1 (patch) | |
tree | 7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /auto_tests/toxav_basic_test.c | |
parent | 4e6c86d1cb228308678f89ff6e4e09b3f46347aa (diff) |
Improve static and const correctness.
- Any non-externally-visible declarations should be `static`.
- Casting away the `const` qualifier from pointers-to-const is
dangerous. All but one instance of this are now correct. The one
instance where we can't keep `const` is one where toxav code actually
writes to a chunk of memory marked as `const`. This code also assumes
4 byte alignment of data packets. I don't know whether that is a valid
assumption, but it's likely unportable, and *not* obviously correct.
- Replaced empty parameter lists with `(void)` to avoid passing
parameters to it. Empty parameter lists are old style declarations for
unknown number and type of arguments.
- Commented out (as `#if DHT_HARDENING` block) the hardening code that
was never executed.
- Minor style fix: don't use `default` in enum-switches unless the number
of enumerators in the default case is very large. In this case, it was
2, so we want to list them both explicitly to be warned about missing
one if we add one in the future.
- Removed the only two function declarations from nTox.h and put them
into nTox.c. They are not used outside and nTox is not a library.
Diffstat (limited to 'auto_tests/toxav_basic_test.c')
-rw-r--r-- | auto_tests/toxav_basic_test.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index e3c4447e..399eac68 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -6,7 +6,7 @@ | |||
6 | # include <assert.h> | 6 | # include <assert.h> |
7 | 7 | ||
8 | # define ck_assert(X) assert(X); | 8 | # define ck_assert(X) assert(X); |
9 | # define START_TEST(NAME) void NAME () | 9 | # define START_TEST(NAME) static void NAME (void) |
10 | # define END_TEST | 10 | # define END_TEST |
11 | #else | 11 | #else |
12 | # include "helpers.h" | 12 | # include "helpers.h" |
@@ -66,7 +66,7 @@ typedef struct { | |||
66 | /** | 66 | /** |
67 | * Callbacks | 67 | * Callbacks |
68 | */ | 68 | */ |
69 | void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | 69 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) |
70 | { | 70 | { |
71 | (void) av; | 71 | (void) av; |
72 | (void) friend_number; | 72 | (void) friend_number; |
@@ -76,7 +76,7 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool | |||
76 | printf("Handling CALL callback\n"); | 76 | printf("Handling CALL callback\n"); |
77 | ((CallControl *)user_data)->incoming = true; | 77 | ((CallControl *)user_data)->incoming = true; |
78 | } | 78 | } |
79 | void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) | 79 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
80 | { | 80 | { |
81 | (void) av; | 81 | (void) av; |
82 | (void) friend_number; | 82 | (void) friend_number; |
@@ -84,11 +84,11 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo | |||
84 | printf("Handling CALL STATE callback: %d\n", state); | 84 | printf("Handling CALL STATE callback: %d\n", state); |
85 | ((CallControl *)user_data)->state = state; | 85 | ((CallControl *)user_data)->state = state; |
86 | } | 86 | } |
87 | void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | 87 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
88 | uint16_t width, uint16_t height, | 88 | uint16_t width, uint16_t height, |
89 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | 89 | uint8_t const *y, uint8_t const *u, uint8_t const *v, |
90 | int32_t ystride, int32_t ustride, int32_t vstride, | 90 | int32_t ystride, int32_t ustride, int32_t vstride, |
91 | void *user_data) | 91 | void *user_data) |
92 | { | 92 | { |
93 | (void) av; | 93 | (void) av; |
94 | (void) friend_number; | 94 | (void) friend_number; |
@@ -103,12 +103,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | |||
103 | (void) user_data; | 103 | (void) user_data; |
104 | printf("Received video payload\n"); | 104 | printf("Received video payload\n"); |
105 | } | 105 | } |
106 | void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | 106 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
107 | int16_t const *pcm, | 107 | int16_t const *pcm, |
108 | size_t sample_count, | 108 | size_t sample_count, |
109 | uint8_t channels, | 109 | uint8_t channels, |
110 | uint32_t sampling_rate, | 110 | uint32_t sampling_rate, |
111 | void *user_data) | 111 | void *user_data) |
112 | { | 112 | { |
113 | (void) av; | 113 | (void) av; |
114 | (void) friend_number; | 114 | (void) friend_number; |
@@ -119,7 +119,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | |||
119 | (void) user_data; | 119 | (void) user_data; |
120 | printf("Received audio payload\n"); | 120 | printf("Received audio payload\n"); |
121 | } | 121 | } |
122 | void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 122 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
123 | void *userdata) | ||
123 | { | 124 | { |
124 | (void) userdata; | 125 | (void) userdata; |
125 | 126 | ||
@@ -132,7 +133,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t | |||
132 | /** | 133 | /** |
133 | * Iterate helper | 134 | * Iterate helper |
134 | */ | 135 | */ |
135 | int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) | 136 | static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) |
136 | { | 137 | { |
137 | c_sleep(100); | 138 | c_sleep(100); |
138 | tox_iterate(bootstrap, NULL); | 139 | tox_iterate(bootstrap, NULL); |
@@ -175,7 +176,7 @@ START_TEST(test_AV_flows) | |||
175 | tox_self_get_address(Alice, address); | 176 | tox_self_get_address(Alice, address); |
176 | 177 | ||
177 | 178 | ||
178 | ck_assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 179 | ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); |
179 | 180 | ||
180 | uint8_t off = 1; | 181 | uint8_t off = 1; |
181 | 182 | ||
@@ -601,7 +602,7 @@ int main(int argc, char *argv[]) | |||
601 | return 0; | 602 | return 0; |
602 | } | 603 | } |
603 | #else | 604 | #else |
604 | Suite *tox_suite(void) | 605 | static Suite *tox_suite(void) |
605 | { | 606 | { |
606 | Suite *s = suite_create("ToxAV"); | 607 | Suite *s = suite_create("ToxAV"); |
607 | 608 | ||