summaryrefslogtreecommitdiff
path: root/auto_tests/toxav_many_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-05 16:10:48 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-06 11:54:37 +0100
commitad2656051697899e960694bb68ac104fcc5e92f1 (patch)
tree7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /auto_tests/toxav_many_test.c
parent4e6c86d1cb228308678f89ff6e4e09b3f46347aa (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_many_test.c')
-rw-r--r--auto_tests/toxav_many_test.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index 5d889032..e3dd5a42 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_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"
@@ -52,7 +52,7 @@ typedef struct {
52/** 52/**
53 * Callbacks 53 * Callbacks
54 */ 54 */
55void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) 55static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
56{ 56{
57 (void) av; 57 (void) av;
58 (void) audio_enabled; 58 (void) audio_enabled;
@@ -61,16 +61,16 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool
61 printf("Handling CALL callback\n"); 61 printf("Handling CALL callback\n");
62 ((CallControl *)user_data)[friend_number].incoming = true; 62 ((CallControl *)user_data)[friend_number].incoming = true;
63} 63}
64void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) 64static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
65{ 65{
66 printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); 66 printf("Handling CALL STATE callback: %d %p\n", state, (void *)av);
67 ((CallControl *)user_data)[friend_number].state = state; 67 ((CallControl *)user_data)[friend_number].state = state;
68} 68}
69void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, 69static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
70 uint16_t width, uint16_t height, 70 uint16_t width, uint16_t height,
71 uint8_t const *y, uint8_t const *u, uint8_t const *v, 71 uint8_t const *y, uint8_t const *u, uint8_t const *v,
72 int32_t ystride, int32_t ustride, int32_t vstride, 72 int32_t ystride, int32_t ustride, int32_t vstride,
73 void *user_data) 73 void *user_data)
74{ 74{
75 (void) av; 75 (void) av;
76 (void) friend_number; 76 (void) friend_number;
@@ -84,12 +84,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
84 (void) vstride; 84 (void) vstride;
85 (void) user_data; 85 (void) user_data;
86} 86}
87void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, 87static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
88 int16_t const *pcm, 88 int16_t const *pcm,
89 size_t sample_count, 89 size_t sample_count,
90 uint8_t channels, 90 uint8_t channels,
91 uint32_t sampling_rate, 91 uint32_t sampling_rate,
92 void *user_data) 92 void *user_data)
93{ 93{
94 (void) av; 94 (void) av;
95 (void) friend_number; 95 (void) friend_number;
@@ -99,7 +99,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
99 (void) sampling_rate; 99 (void) sampling_rate;
100 (void) user_data; 100 (void) user_data;
101} 101}
102void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) 102static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length,
103 void *userdata)
103{ 104{
104 (void) userdata; 105 (void) userdata;
105 106
@@ -112,7 +113,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t
112/** 113/**
113 * Iterate helper 114 * Iterate helper
114 */ 115 */
115ToxAV *setup_av_instance(Tox *tox, CallControl *CC) 116static ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
116{ 117{
117 TOXAV_ERR_NEW error; 118 TOXAV_ERR_NEW error;
118 119
@@ -126,7 +127,7 @@ ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
126 127
127 return av; 128 return av;
128} 129}
129void *call_thread(void *pd) 130static void *call_thread(void *pd)
130{ 131{
131 ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; 132 ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
132 ToxAV *BobAV = ((thread_data *) pd)->BobAV; 133 ToxAV *BobAV = ((thread_data *) pd)->BobAV;
@@ -241,9 +242,9 @@ START_TEST(test_AV_three_calls)
241 tox_self_get_address(Alice, address); 242 tox_self_get_address(Alice, address);
242 243
243 244
244 ck_assert(tox_friend_add(Bobs[0], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); 245 ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
245 ck_assert(tox_friend_add(Bobs[1], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); 246 ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
246 ck_assert(tox_friend_add(Bobs[2], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); 247 ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
247 248
248 uint8_t off = 1; 249 uint8_t off = 1;
249 250
@@ -351,7 +352,7 @@ int main(int argc, char *argv[])
351 return 0; 352 return 0;
352} 353}
353#else 354#else
354Suite *tox_suite(void) 355static Suite *tox_suite(void)
355{ 356{
356 Suite *s = suite_create("ToxAV"); 357 Suite *s = suite_create("ToxAV");
357 358