Skip to content

Commit e53020c

Browse files
iphydfzoff99
authored andcommitted
cleanup: Add const where possible in auto tests.
Also one in `DHT_bootstrap.c`.
1 parent e60ae0b commit e53020c

17 files changed

+42
-41
lines changed

auto_tests/TCP_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ static void test_client(void)
582582
do_tcp_connection(logger, mono_time, conn2, nullptr);
583583
c_sleep(50);
584584

585-
uint8_t data[5] = {1, 2, 3, 4, 5};
585+
const uint8_t data[5] = {1, 2, 3, 4, 5};
586586
memcpy(oob_pubkey, f2_public_key, CRYPTO_PUBLIC_KEY_SIZE);
587587
send_oob_packet(logger, conn2, f_public_key, data, 5);
588588
send_routing_request(logger, conn, f2_public_key);

auto_tests/auto_test_support.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTo
335335
}
336336
}
337337

338-
static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count, const Run_Auto_Options *autotest_opts,
338+
static void bootstrap_autotoxes(const Tox_Options *options, uint32_t tox_count, const Run_Auto_Options *autotest_opts,
339339
AutoTox *autotoxes)
340340
{
341341
const bool udp_enabled = options != nullptr ? tox_options_get_udp_enabled(options) : true;
@@ -363,7 +363,9 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count,
363363
}
364364
}
365365

366-
void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void test(AutoTox *autotoxes),
366+
typedef void autotox_test_cb(AutoTox *autotoxes);
367+
368+
void run_auto_test(struct Tox_Options *options, uint32_t tox_count, autotox_test_cb *test,
367369
uint32_t state_size, Run_Auto_Options *autotest_opts)
368370
{
369371
printf("initialising %u toxes\n", tox_count);

auto_tests/conference_av_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void handle_conference_connected(
108108
}
109109

110110
static bool toxes_are_disconnected_from_group(uint32_t tox_count, AutoTox *autotoxes,
111-
bool *disconnected)
111+
const bool *disconnected)
112112
{
113113
uint32_t num_disconnected = 0;
114114

@@ -177,7 +177,7 @@ static bool all_connected_to_group(uint32_t tox_count, AutoTox *autotoxes)
177177
* returns a random index at which a list of booleans is false
178178
* (some such index is required to exist)
179179
*/
180-
static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length)
180+
static uint32_t random_false_index(const Random *rng, const bool *list, const uint32_t length)
181181
{
182182
uint32_t index;
183183

@@ -197,7 +197,7 @@ static bool all_got_audio(AutoTox *autotoxes, const bool *disabled)
197197
}
198198

199199
for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) {
200-
State *state = (State *)autotoxes[i].state;
200+
const State *state = (const State *)autotoxes[i].state;
201201

202202
if (disabled[i] ^ (state->received_audio_num
203203
!= NUM_AV_GROUP_TOX - num_disabled - 1)) {

auto_tests/conference_invite_merge_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void handle_conference_connected(
4040
state->connected = true;
4141
}
4242

43-
static void wait_connected(AutoTox *autotoxes, AutoTox *autotox, uint32_t friendnumber)
43+
static void wait_connected(AutoTox *autotoxes, const AutoTox *autotox, uint32_t friendnumber)
4444
{
4545
do {
4646
iterate_all_wait(autotoxes, NUM_INVITE_MERGE_TOX, ITERATION_INTERVAL);

auto_tests/conference_simple_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void handle_conference_connected(Tox *tox, const Tox_Event_Conference_Con
116116
}
117117

118118
static void iterate_one(
119-
Tox *tox, State *state, Tox_Dispatch *dispatch)
119+
Tox *tox, State *state, const Tox_Dispatch *dispatch)
120120
{
121121
Tox_Err_Events_Iterate err;
122122
Tox_Events *events = tox_events_iterate(tox, true, &err);
@@ -129,7 +129,7 @@ static void iterate3_wait(
129129
Tox *tox1, State *state1,
130130
Tox *tox2, State *state2,
131131
Tox *tox3, State *state3,
132-
Tox_Dispatch *dispatch, int interval)
132+
const Tox_Dispatch *dispatch, int interval)
133133
{
134134
iterate_one(tox1, state1, dispatch);
135135
iterate_one(tox2, state2, dispatch);

auto_tests/conference_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void handle_conference_message(
9797
}
9898

9999
static bool toxes_are_disconnected_from_group(uint32_t tox_count, AutoTox *autotoxes,
100-
bool *disconnected)
100+
const bool *disconnected)
101101
{
102102
uint32_t num_disconnected = 0;
103103

@@ -179,7 +179,7 @@ static bool names_propagated(uint32_t tox_count, AutoTox *autotoxes)
179179
* returns a random index at which a list of booleans is false
180180
* (some such index is required to exist)
181181
*/
182-
static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length)
182+
static uint32_t random_false_index(const Random *rng, const bool *list, const uint32_t length)
183183
{
184184
uint32_t index;
185185

auto_tests/crypto_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static void test_very_large_data(void)
274274
const Random *rng = os_random();
275275
ck_assert(rng != nullptr);
276276

277-
uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
277+
const uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
278278
uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE];
279279
uint8_t sk[CRYPTO_SECRET_KEY_SIZE];
280280
crypto_new_keypair(rng, pk, sk);

auto_tests/file_streaming_test.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
5353

5454
ck_assert_msg(memcmp(file_id, file_cmp_id, TOX_FILE_ID_LENGTH) == 0, "bad file_id");
5555

56-
uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
56+
const uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
5757

5858
ck_assert_msg(memcmp(empty, file_cmp_id, TOX_FILE_ID_LENGTH) != 0, "empty file_id");
5959

@@ -209,7 +209,6 @@ static void file_transfer_test(void)
209209
file_accepted = file_size = sendf_ok = size_recv = 0;
210210
file_recv = 0;
211211
max_sending = UINT64_MAX;
212-
uint64_t totalf_size = 100 * 1024 * 1024;
213212

214213
printf("Starting file streaming transfer test.\n");
215214

@@ -224,7 +223,7 @@ static void file_transfer_test(void)
224223
tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
225224
tox_callback_file_recv_control(tox3, file_print_control);
226225
tox_callback_file_recv(tox3, tox_file_receive);
227-
totalf_size = UINT64_MAX;
226+
const uint64_t totalf_size = UINT64_MAX;
228227
Tox_File_Number fnum = tox_file_send(
229228
tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr,
230229
(const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr);

auto_tests/file_transfer_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void tox_file_receive(Tox *tox, const Tox_Event_File_Recv *event, void *u
6363

6464
ck_assert_msg(memcmp(file_id, file_cmp_id, TOX_FILE_ID_LENGTH) == 0, "bad file_id");
6565

66-
uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
66+
const uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
6767

6868
ck_assert_msg(memcmp(empty, file_cmp_id, TOX_FILE_ID_LENGTH) != 0, "empty file_id");
6969

@@ -175,7 +175,7 @@ static void write_file(Tox *tox, const Tox_Event_File_Recv_Chunk *event, void *u
175175
size_recv += length;
176176
}
177177

178-
static void iterate_and_dispatch(Tox_Dispatch *dispatch, Tox *tox)
178+
static void iterate_and_dispatch(const Tox_Dispatch *dispatch, Tox *tox)
179179
{
180180
Tox_Err_Events_Iterate err;
181181
Tox_Events *events;

auto_tests/forwarding_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static void test_forwarded_request_cb(void *object, const IP_Port *forwarder,
4747
const uint8_t *sendback, uint16_t sendback_length,
4848
const uint8_t *data, uint16_t length, void *userdata)
4949
{
50-
Test_Data *test_data = (Test_Data *)object;
51-
uint8_t *index = (uint8_t *)userdata;
50+
const Test_Data *test_data = (const Test_Data *)object;
51+
const uint8_t *index = (const uint8_t *)userdata;
5252

5353
if (length != 12 || memcmp("hello: ", data, 8) != 0) {
5454
printf("[%u] got unexpected data of length %d\n", *index, length);
@@ -66,7 +66,7 @@ static void test_forwarded_response_cb(void *object,
6666
const uint8_t *data, uint16_t length, void *userdata)
6767
{
6868
Test_Data *test_data = (Test_Data *)object;
69-
uint8_t *index = (uint8_t *)userdata;
69+
const uint8_t *index = (const uint8_t *)userdata;
7070

7171
if (length != 12 || memcmp("reply: ", data, 8) != 0) {
7272
printf("[%u] got unexpected data of length %d\n", *index, length);

0 commit comments

Comments
 (0)