diff --git a/auto_tests/conference_av_test.c b/auto_tests/conference_av_test.c index ac6f1e3db3..1c9580cb40 100644 --- a/auto_tests/conference_av_test.c +++ b/auto_tests/conference_av_test.c @@ -85,7 +85,7 @@ static void handle_conference_invite( ck_assert_msg(type == TOX_CONFERENCE_TYPE_AV, "tox #%u: wrong conference type: %d", autotox->index, type); - ck_assert_msg(toxav_join_av_groupchat(tox, friend_number, cookie, length, audio_callback, user_data) == 0, + ck_assert_msg(toxav_join_av_groupchat(autotox->tox, friend_number, cookie, length, audio_callback, user_data) == 0, "tox #%u: failed to join group", autotox->index); } @@ -95,12 +95,12 @@ static void handle_conference_connected( const AutoTox *autotox = (AutoTox *)user_data; State *state = (State *)autotox->state; - if (state->invited_next || tox_self_get_friend_list_size(tox) <= 1) { + if (state->invited_next || tox_self_get_friend_list_size(autotox->tox) <= 1) { return; } Tox_Err_Conference_Invite err; - tox_conference_invite(tox, 1, 0, &err); + tox_conference_invite(autotox->tox, 1, 0, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index, err); printf("tox #%u: invited next friend\n", autotox->index); diff --git a/auto_tests/conference_double_invite_test.c b/auto_tests/conference_double_invite_test.c index bda1c74e35..ff457924da 100644 --- a/auto_tests/conference_double_invite_test.c +++ b/auto_tests/conference_double_invite_test.c @@ -30,7 +30,7 @@ static void handle_conference_invite( if (friend_number != -1) { Tox_Err_Conference_Join err; - state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); + state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "attempting to join the conference returned with an error: %d", err); fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference); diff --git a/auto_tests/conference_invite_merge_test.c b/auto_tests/conference_invite_merge_test.c index c9b6a73ac0..c6a9da2512 100644 --- a/auto_tests/conference_invite_merge_test.c +++ b/auto_tests/conference_invite_merge_test.c @@ -23,7 +23,7 @@ static void handle_conference_invite( if (friend_number != -1) { Tox_Err_Conference_Join err; - state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); + state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "attempting to join the conference returned with an error: %d", err); fprintf(stderr, "#%u accepted invite to conference %u\n", autotox->index, state->conference); diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c index 1414ebe94e..72d6236c6b 100644 --- a/auto_tests/conference_peer_nick_test.c +++ b/auto_tests/conference_peer_nick_test.c @@ -28,7 +28,7 @@ static void handle_conference_invite( fprintf(stderr, "tox%u joining conference\n", autotox->index); Tox_Err_Conference_Join err; - state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); + state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "attempting to join the conference returned with an error: %d", err); fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference); @@ -45,7 +45,7 @@ static void handle_peer_list_changed(Tox *tox, const Tox_Event_Conference_Peer_L autotox->index, conference_number); Tox_Err_Conference_Peer_Query err; - uint32_t const count = tox_conference_peer_count(tox, conference_number, &err); + uint32_t const count = tox_conference_peer_count(autotox->tox, conference_number, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, "failed to get conference peer count: err = %d", err); printf("tox%u has %u peers\n", autotox->index, count); diff --git a/auto_tests/conference_simple_test.c b/auto_tests/conference_simple_test.c index 6b9290ea42..3d03e50f07 100644 --- a/auto_tests/conference_simple_test.c +++ b/auto_tests/conference_simple_test.c @@ -10,6 +10,7 @@ typedef struct State { uint32_t id; + Tox *tox; bool self_online; bool friend_online; bool invited_next; @@ -56,7 +57,7 @@ static void handle_conference_invite(Tox *tox, const Tox_Event_Conference_Invite { Tox_Err_Conference_Join err; - state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); + state->conference = tox_conference_join(state->tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err); fprintf(stderr, "tox%u Joined conference %u\n", state->id, state->conference); state->joined = true; @@ -89,7 +90,7 @@ static void handle_conference_peer_list_changed(Tox *tox, const Tox_Event_Confer state->id, conference_number); Tox_Err_Conference_Peer_Query err; - uint32_t count = tox_conference_peer_count(tox, conference_number, &err); + uint32_t count = tox_conference_peer_count(state->tox, conference_number, &err); if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) { fprintf(stderr, "ERROR: %d\n", err); @@ -107,7 +108,7 @@ static void handle_conference_connected(Tox *tox, const Tox_Event_Conference_Con // We're tox2, so now we invite tox3. if (state->id == 2 && !state->invited_next) { Tox_Err_Conference_Invite err; - tox_conference_invite(tox, 1, state->conference, &err); + tox_conference_invite(state->tox, 1, state->conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %d", err); state->invited_next = true; @@ -126,14 +127,12 @@ static void iterate_one( } static void iterate3_wait( - Tox *tox1, State *state1, - Tox *tox2, State *state2, - Tox *tox3, State *state3, + State *state1, State *state2, State *state3, const Tox_Dispatch *dispatch, int interval) { - iterate_one(tox1, state1, dispatch); - iterate_one(tox2, state2, dispatch); - iterate_one(tox3, state3, dispatch); + iterate_one(state1->tox, state1, dispatch); + iterate_one(state2->tox, state2, dispatch); + iterate_one(state3->tox, state3, dispatch); c_sleep(interval); } @@ -147,32 +146,32 @@ int main(void) State state3 = {3}; // Create toxes. - Tox *tox1 = tox_new_log(nullptr, nullptr, &state1.id); - Tox *tox2 = tox_new_log(nullptr, nullptr, &state2.id); - Tox *tox3 = tox_new_log(nullptr, nullptr, &state3.id); + state1.tox = tox_new_log(nullptr, nullptr, &state1.id); + state2.tox = tox_new_log(nullptr, nullptr, &state2.id); + state3.tox = tox_new_log(nullptr, nullptr, &state3.id); - tox_events_init(tox1); - tox_events_init(tox2); - tox_events_init(tox3); + tox_events_init(state1.tox); + tox_events_init(state2.tox); + tox_events_init(state3.tox); // tox1 <-> tox2, tox2 <-> tox3 uint8_t key[TOX_PUBLIC_KEY_SIZE]; - tox_self_get_public_key(tox2, key); - tox_friend_add_norequest(tox1, key, nullptr); // tox1 -> tox2 - tox_self_get_public_key(tox1, key); - tox_friend_add_norequest(tox2, key, nullptr); // tox2 -> tox1 - tox_self_get_public_key(tox3, key); - tox_friend_add_norequest(tox2, key, nullptr); // tox2 -> tox3 - tox_self_get_public_key(tox2, key); - tox_friend_add_norequest(tox3, key, nullptr); // tox3 -> tox2 + tox_self_get_public_key(state2.tox, key); + tox_friend_add_norequest(state1.tox, key, nullptr); // tox1 -> tox2 + tox_self_get_public_key(state1.tox, key); + tox_friend_add_norequest(state2.tox, key, nullptr); // tox2 -> tox1 + tox_self_get_public_key(state3.tox, key); + tox_friend_add_norequest(state2.tox, key, nullptr); // tox2 -> tox3 + tox_self_get_public_key(state2.tox, key); + tox_friend_add_norequest(state3.tox, key, nullptr); // tox3 -> tox2 printf("bootstrapping tox2 and tox3 off tox1\n"); uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; - tox_self_get_dht_id(tox1, dht_key); - const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); + tox_self_get_dht_id(state1.tox, dht_key); + const uint16_t dht_port = tox_self_get_udp_port(state1.tox, nullptr); - tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); - tox_bootstrap(tox3, "localhost", dht_port, dht_key, nullptr); + tox_bootstrap(state2.tox, "localhost", dht_port, dht_key, nullptr); + tox_bootstrap(state3.tox, "localhost", dht_port, dht_key, nullptr); Tox_Dispatch *dispatch = tox_dispatch_new(nullptr); ck_assert(dispatch != nullptr); @@ -191,7 +190,7 @@ int main(void) fprintf(stderr, "Waiting for toxes to come online\n"); do { - iterate3_wait(tox1, &state1, tox2, &state2, tox3, &state3, dispatch, 100); + iterate3_wait(&state1, &state2, &state3, dispatch, 100); } while (!state1.self_online || !state2.self_online || !state3.self_online); fprintf(stderr, "Toxes are online\n"); @@ -200,7 +199,7 @@ int main(void) fprintf(stderr, "Waiting for friends to connect\n"); do { - iterate3_wait(tox1, &state1, tox2, &state2, tox3, &state3, dispatch, 100); + iterate3_wait(&state1, &state2, &state3, dispatch, 100); } while (!state1.friend_online || !state2.friend_online || !state3.friend_online); fprintf(stderr, "Friends are connected\n"); @@ -208,7 +207,7 @@ int main(void) { // Create new conference, tox1 is the founder. Tox_Err_Conference_New err; - state1.conference = tox_conference_new(tox1, &err); + state1.conference = tox_conference_new(state1.tox, &err); state1.joined = true; ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err); fprintf(stderr, "Created conference: id = %u\n", state1.conference); @@ -217,7 +216,7 @@ int main(void) { // Invite friend. Tox_Err_Conference_Invite err; - tox_conference_invite(tox1, 0, state1.conference, &err); + tox_conference_invite(state1.tox, 0, state1.conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err); state1.invited_next = true; fprintf(stderr, "tox1 invited tox2\n"); @@ -226,7 +225,7 @@ int main(void) fprintf(stderr, "Waiting for invitation to arrive\n"); do { - iterate3_wait(tox1, &state1, tox2, &state2, tox3, &state3, dispatch, 100); + iterate3_wait(&state1, &state2, &state3, dispatch, 100); } while (!state1.joined || !state2.joined || !state3.joined); fprintf(stderr, "Invitations accepted\n"); @@ -234,7 +233,7 @@ int main(void) fprintf(stderr, "Waiting for peers to come online\n"); do { - iterate3_wait(tox1, &state1, tox2, &state2, tox3, &state3, dispatch, 100); + iterate3_wait(&state1, &state2, &state3, dispatch, 100); } while (state1.peers == 0 || state2.peers == 0 || state3.peers == 0); fprintf(stderr, "All peers are online\n"); @@ -242,7 +241,7 @@ int main(void) { fprintf(stderr, "tox1 sends a message to the group: \"hello!\"\n"); Tox_Err_Conference_Send_Message err; - tox_conference_send_message(tox1, state1.conference, TOX_MESSAGE_TYPE_NORMAL, + tox_conference_send_message(state1.tox, state1.conference, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"hello!", 7, &err); if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) { @@ -254,16 +253,16 @@ int main(void) fprintf(stderr, "Waiting for messages to arrive\n"); do { - iterate3_wait(tox1, &state1, tox2, &state2, tox3, &state3, dispatch, 100); + iterate3_wait(&state1, &state2, &state3, dispatch, 100); c_sleep(100); } while (!state2.received || !state3.received); fprintf(stderr, "Messages received. Test complete.\n"); tox_dispatch_free(dispatch); - tox_kill(tox3); - tox_kill(tox2); - tox_kill(tox1); + tox_kill(state3.tox); + tox_kill(state2.tox); + tox_kill(state1.tox); return 0; } diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index 0ecca27040..af1cd288f8 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -56,13 +56,13 @@ static void handle_conference_invite( ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%u: wrong conference type: %d", autotox->index, type); Tox_Err_Conference_Join err; - uint32_t g_num = tox_conference_join(tox, friendnumber, data, length, &err); + uint32_t g_num = tox_conference_join(autotox->tox, friendnumber, data, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "tox #%u: error joining group: %d", autotox->index, err); ck_assert_msg(g_num == 0, "tox #%u: group number was not 0", autotox->index); // Try joining again. We should only be allowed to join once. - tox_conference_join(tox, friendnumber, data, length, &err); + tox_conference_join(autotox->tox, friendnumber, data, length, &err); ck_assert_msg(err != TOX_ERR_CONFERENCE_JOIN_OK, "tox #%u: joining groupchat twice should be impossible.", autotox->index); } @@ -73,12 +73,12 @@ static void handle_conference_connected( const AutoTox *autotox = (AutoTox *)user_data; State *state = (State *)autotox->state; - if (state->invited_next || tox_self_get_friend_list_size(tox) <= 1) { + if (state->invited_next || tox_self_get_friend_list_size(autotox->tox) <= 1) { return; } Tox_Err_Conference_Invite err; - tox_conference_invite(tox, 1, 0, &err); + tox_conference_invite(autotox->tox, 1, 0, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index, err); printf("tox #%u: invited next friend\n", autotox->index); diff --git a/auto_tests/dht_getnodes_api_test.c b/auto_tests/dht_getnodes_api_test.c index 7b5ce3db74..ea930577f9 100644 --- a/auto_tests/dht_getnodes_api_test.c +++ b/auto_tests/dht_getnodes_api_test.c @@ -76,8 +76,8 @@ static void getnodes_response_cb(Tox *tox, const Tox_Event_Dht_Get_Nodes_Respons { ck_assert(user_data != nullptr); - AutoTox *autotoxes = (AutoTox *)user_data; - State *state = (State *)autotoxes->state; + AutoTox *autotox = (AutoTox *)user_data; + State *state = (State *)autotox->state; const uint8_t *public_key = tox_event_dht_get_nodes_response_get_public_key(event); const char *ip = (const char *)tox_event_dht_get_nodes_response_get_ip(event); @@ -101,7 +101,7 @@ static void getnodes_response_cb(Tox *tox, const Tox_Event_Dht_Get_Nodes_Respons // ask new node to give us their close nodes to every public key for (size_t i = 0; i < NUM_TOXES; ++i) { - tox_dht_get_nodes(tox, public_key, ip, port, state->public_key_list[i], nullptr); + tox_dht_get_nodes(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr); } } diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c index aacd0b1037..a18fc6525f 100644 --- a/auto_tests/file_transfer_test.c +++ b/auto_tests/file_transfer_test.c @@ -28,12 +28,14 @@ static void accept_friend_request(Tox *m, const Tox_Event_Friend_Request *event, void *userdata) { + Tox *tox = (Tox *)userdata; + const uint8_t *public_key = tox_event_friend_request_get_public_key(event); const uint8_t *data = tox_event_friend_request_get_message(event); const size_t length = tox_event_friend_request_get_message_length(event); if (length == 7 && memcmp("Gentoo", data, 7) == 0) { - tox_friend_add_norequest(m, public_key, nullptr); + tox_friend_add_norequest(tox, public_key, nullptr); } } @@ -45,6 +47,8 @@ static uint32_t file_accepted; static uint64_t file_size; static void tox_file_receive(Tox *tox, const Tox_Event_File_Recv *event, void *userdata) { + Tox *state_tox = (Tox *)userdata; + const uint32_t friend_number = tox_event_file_recv_get_friend_number(event); const uint32_t file_number = tox_event_file_recv_get_file_number(event); const uint32_t kind = tox_event_file_recv_get_kind(event); @@ -59,7 +63,7 @@ static void tox_file_receive(Tox *tox, const Tox_Event_File_Recv *event, void *u uint8_t file_id[TOX_FILE_ID_LENGTH]; - ck_assert_msg(tox_file_get_file_id(tox, friend_number, file_number, file_id, nullptr), "tox_file_get_file_id error"); + ck_assert_msg(tox_file_get_file_id(state_tox, friend_number, file_number, file_id, nullptr), "tox_file_get_file_id error"); ck_assert_msg(memcmp(file_id, file_cmp_id, TOX_FILE_ID_LENGTH) == 0, "bad file_id"); @@ -74,7 +78,7 @@ static void tox_file_receive(Tox *tox, const Tox_Event_File_Recv *event, void *u Tox_Err_File_Seek err_s; - ck_assert_msg(tox_file_seek(tox, friend_number, file_number, 1337, &err_s), "tox_file_seek error"); + ck_assert_msg(tox_file_seek(state_tox, friend_number, file_number, 1337, &err_s), "tox_file_seek error"); ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_OK, "tox_file_seek wrong error"); @@ -84,13 +88,13 @@ static void tox_file_receive(Tox *tox, const Tox_Event_File_Recv *event, void *u Tox_Err_File_Control error; - ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error), + ck_assert_msg(tox_file_control(state_tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error), "tox_file_control failed. %i", error); ++file_accepted; Tox_Err_File_Seek err_s; - ck_assert_msg(!tox_file_seek(tox, friend_number, file_number, 1234, &err_s), "tox_file_seek no error"); + ck_assert_msg(!tox_file_seek(state_tox, friend_number, file_number, 1234, &err_s), "tox_file_seek no error"); ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_DENIED, "tox_file_seek wrong error"); } @@ -114,6 +118,8 @@ static uint8_t sending_num; static bool file_sending_done; static void tox_file_chunk_request(Tox *tox, const Tox_Event_File_Chunk_Request *event, void *user_data) { + Tox *state_tox = (Tox *)user_data; + const uint32_t friend_number = tox_event_file_chunk_request_get_friend_number(event); const uint32_t file_number = tox_event_file_chunk_request_get_file_number(event); const uint64_t position = tox_event_file_chunk_request_get_position(event); @@ -141,7 +147,7 @@ static void tox_file_chunk_request(Tox *tox, const Tox_Event_File_Chunk_Request memset(f_data, sending_num, length); Tox_Err_File_Send_Chunk error; - tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error); + tox_file_send_chunk(state_tox, friend_number, file_number, position, f_data, length, &error); ck_assert_msg(error == TOX_ERR_FILE_SEND_CHUNK_OK, "could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length); @@ -181,7 +187,7 @@ static void iterate_and_dispatch(const Tox_Dispatch *dispatch, Tox *tox) events = tox_events_iterate(tox, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch, events, tox, nullptr); + tox_dispatch_invoke(dispatch, events, tox, tox); tox_events_free(events); } diff --git a/auto_tests/friend_request_spam_test.c b/auto_tests/friend_request_spam_test.c index c90c3ec101..d01de46ed0 100644 --- a/auto_tests/friend_request_spam_test.c +++ b/auto_tests/friend_request_spam_test.c @@ -25,13 +25,15 @@ typedef struct State { static void accept_friend_request(Tox *tox, const Tox_Event_Friend_Request *event, void *userdata) { + AutoTox *autotox = (AutoTox *)userdata; + const uint8_t *public_key = tox_event_friend_request_get_public_key(event); const uint8_t *data = tox_event_friend_request_get_message(event); const size_t length = tox_event_friend_request_get_message_length(event); ck_assert_msg(length == sizeof(FR_MESSAGE) && memcmp(FR_MESSAGE, data, sizeof(FR_MESSAGE)) == 0, "unexpected friend request message"); - tox_friend_add_norequest(tox, public_key, nullptr); + tox_friend_add_norequest(autotox->tox, public_key, nullptr); } static void test_friend_request(AutoTox *autotoxes) diff --git a/auto_tests/friend_request_test.c b/auto_tests/friend_request_test.c index 1e0f675a19..d28161cda1 100644 --- a/auto_tests/friend_request_test.c +++ b/auto_tests/friend_request_test.c @@ -18,12 +18,15 @@ static void accept_friend_request(Tox *tox, const Tox_Event_Friend_Request *event, void *userdata) { + Tox *state_tox = (Tox *)userdata; + const uint8_t *public_key = tox_event_friend_request_get_public_key(event); const uint8_t *data = tox_event_friend_request_get_message(event); const size_t length = tox_event_friend_request_get_message_length(event); + ck_assert_msg(length == sizeof(FR_MESSAGE) && memcmp(FR_MESSAGE, data, sizeof(FR_MESSAGE)) == 0, "unexpected friend request message"); - tox_friend_add_norequest(tox, public_key, nullptr); + tox_friend_add_norequest(state_tox, public_key, nullptr); } static void iterate2_wait(const Tox_Dispatch *dispatch, Tox *tox1, Tox *tox2) @@ -33,12 +36,12 @@ static void iterate2_wait(const Tox_Dispatch *dispatch, Tox *tox1, Tox *tox2) events = tox_events_iterate(tox1, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch, events, tox1, nullptr); + tox_dispatch_invoke(dispatch, events, tox1, tox1); tox_events_free(events); events = tox_events_iterate(tox2, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch, events, tox2, nullptr); + tox_dispatch_invoke(dispatch, events, tox2, tox2); tox_events_free(events); c_sleep(ITERATION_INTERVAL); diff --git a/auto_tests/group_general_test.c b/auto_tests/group_general_test.c index 292b8d534a..333cbe22f2 100644 --- a/auto_tests/group_general_test.c +++ b/auto_tests/group_general_test.c @@ -93,23 +93,23 @@ static void group_peer_join_handler(Tox *tox, const Tox_Event_Group_Peer_Join *e // we do a connection test here for fun Tox_Err_Group_Peer_Query pq_err; - Tox_Connection connection_status = tox_group_peer_get_connection_status(tox, groupnumber, peer_id, &pq_err); + Tox_Connection connection_status = tox_group_peer_get_connection_status(autotox->tox, groupnumber, peer_id, &pq_err); ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(connection_status != TOX_CONNECTION_NONE); - Tox_Group_Role role = tox_group_peer_get_role(tox, groupnumber, peer_id, &pq_err); + Tox_Group_Role role = tox_group_peer_get_role(autotox->tox, groupnumber, peer_id, &pq_err); ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%d", pq_err); - Tox_User_Status status = tox_group_peer_get_status(tox, groupnumber, peer_id, &pq_err); + Tox_User_Status status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &pq_err); ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%d", pq_err); - size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &pq_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &pq_err); char peer_name[TOX_MAX_NAME_LENGTH + 1]; ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); - tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &pq_err); + tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &pq_err); ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK); peer_name[peer_name_len] = 0; @@ -140,7 +140,7 @@ static void group_peer_join_handler(Tox *tox, const Tox_Event_Group_Peer_Join *e } fprintf(stderr, "%s joined with IP: ", peer_name); - print_ip(tox, groupnumber, peer_id); + print_ip(autotox->tox, groupnumber, peer_id); state->peer_id = peer_id; ++state->peer_joined_count; @@ -158,19 +158,19 @@ static void group_peer_self_join_handler(Tox *tox, const Tox_Event_Group_Self_Jo // make sure we see our own correct peer state on join callback Tox_Err_Group_Self_Query sq_err; - size_t self_length = tox_group_self_get_name_size(tox, groupnumber, &sq_err); + size_t self_length = tox_group_self_get_name_size(autotox->tox, groupnumber, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); uint8_t self_name[TOX_MAX_NAME_LENGTH]; - tox_group_self_get_name(tox, groupnumber, self_name, &sq_err); + tox_group_self_get_name(autotox->tox, groupnumber, self_name, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); - Tox_User_Status self_status = tox_group_self_get_status(tox, groupnumber, &sq_err); + Tox_User_Status self_status = tox_group_self_get_status(autotox->tox, groupnumber, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); - Tox_Group_Role self_role = tox_group_self_get_role(tox, groupnumber, &sq_err); + Tox_Group_Role self_role = tox_group_self_get_role(autotox->tox, groupnumber, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); if (state->is_founder) { @@ -190,23 +190,23 @@ static void group_peer_self_join_handler(Tox *tox, const Tox_Event_Group_Self_Jo uint8_t group_name[GROUP_NAME_LEN]; uint8_t topic[TOX_GROUP_MAX_TOPIC_LENGTH]; - ck_assert(tox_group_get_peer_limit(tox, groupnumber, nullptr) == PEER_LIMIT); - ck_assert(tox_group_get_name_size(tox, groupnumber, nullptr) == GROUP_NAME_LEN); - ck_assert(tox_group_get_topic_size(tox, groupnumber, nullptr) == TOPIC_LEN); + ck_assert(tox_group_get_peer_limit(autotox->tox, groupnumber, nullptr) == PEER_LIMIT); + ck_assert(tox_group_get_name_size(autotox->tox, groupnumber, nullptr) == GROUP_NAME_LEN); + ck_assert(tox_group_get_topic_size(autotox->tox, groupnumber, nullptr) == TOPIC_LEN); Tox_Err_Group_State_Queries query_err; - tox_group_get_name(tox, groupnumber, group_name, &query_err); + tox_group_get_name(autotox->tox, groupnumber, group_name, &query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err); ck_assert(memcmp(group_name, GROUP_NAME, GROUP_NAME_LEN) == 0); - tox_group_get_topic(tox, groupnumber, topic, &query_err); + tox_group_get_topic(autotox->tox, groupnumber, topic, &query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err); ck_assert(memcmp(topic, TOPIC, TOPIC_LEN) == 0); - uint32_t peer_id = tox_group_self_get_peer_id(tox, groupnumber, nullptr); + uint32_t peer_id = tox_group_self_get_peer_id(autotox->tox, groupnumber, nullptr); fprintf(stderr, "self joined with IP: "); - print_ip(tox, groupnumber, peer_id); + print_ip(autotox->tox, groupnumber, peer_id); ++state->self_joined_count; } @@ -261,7 +261,7 @@ static void group_peer_status_handler(Tox *tox, const Tox_Event_Group_Peer_Statu const Tox_User_Status status = tox_event_group_peer_status_get_status(event); Tox_Err_Group_Peer_Query err; - Tox_User_Status cur_status = tox_group_peer_get_status(tox, groupnumber, peer_id, &err); + Tox_User_Status cur_status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &err); ck_assert_msg(cur_status == status, "%d, %d", cur_status, status); ck_assert(status == TOX_USER_STATUS_BUSY); diff --git a/auto_tests/group_message_test.c b/auto_tests/group_message_test.c index 39da2c4893..d5816f30bb 100644 --- a/auto_tests/group_message_test.c +++ b/auto_tests/group_message_test.c @@ -73,13 +73,16 @@ static uint16_t get_message_checksum(const uint8_t *message, uint16_t length) static void group_invite_handler(Tox *tox, const Tox_Event_Group_Invite *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t friend_number = tox_event_group_invite_get_friend_number(event); const uint8_t *invite_data = tox_event_group_invite_get_invite_data(event); const size_t length = tox_event_group_invite_get_invite_data_length(event); printf("invite arrived; accepting\n"); Tox_Err_Group_Invite_Accept err_accept; - tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, + tox_group_invite_accept(autotox->tox, friend_number, invite_data, length, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, nullptr, 0, &err_accept); ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK); } @@ -108,6 +111,9 @@ static void group_peer_join_handler(Tox *tox, const Tox_Event_Group_Peer_Join *e static void group_custom_private_packet_handler(Tox *tox, const Tox_Event_Group_Custom_Private_Packet *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_custom_private_packet_get_group_number(event); const uint32_t peer_id = tox_event_group_custom_private_packet_get_peer_id(event); const uint8_t *data = tox_event_group_custom_private_packet_get_data(event); @@ -121,25 +127,25 @@ static void group_custom_private_packet_handler(Tox *tox, const Tox_Event_Group_ message_buf[length] = 0; Tox_Err_Group_Peer_Query q_err; - size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); char peer_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err); + tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err); peer_name[peer_name_len] = 0; ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); Tox_Err_Group_Self_Query s_err; - size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); + size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); char self_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err); + tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err); self_name[self_name_len] = 0; ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); @@ -148,9 +154,6 @@ static void group_custom_private_packet_handler(Tox *tox, const Tox_Event_Group_ printf("%s sent custom private packet to %s: %s\n", peer_name, self_name, message_buf); ck_assert(memcmp(message_buf, TEST_CUSTOM_PRIVATE_PACKET, length) == 0); - AutoTox *autotox = (AutoTox *)user_data; - ck_assert(autotox != nullptr); - State *state = (State *)autotox->state; ++state->custom_private_packets_received; @@ -158,6 +161,9 @@ static void group_custom_private_packet_handler(Tox *tox, const Tox_Event_Group_ static void group_custom_packet_handler(Tox *tox, const Tox_Event_Group_Custom_Packet *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_custom_packet_get_group_number(event); const uint32_t peer_id = tox_event_group_custom_packet_get_peer_id(event); const uint8_t *data = tox_event_group_custom_packet_get_data(event); @@ -170,25 +176,25 @@ static void group_custom_packet_handler(Tox *tox, const Tox_Event_Group_Custom_P message_buf[length] = 0; Tox_Err_Group_Peer_Query q_err; - size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); char peer_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err); + tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &q_err); peer_name[peer_name_len] = 0; ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); Tox_Err_Group_Self_Query s_err; - size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); + size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); char self_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err); + tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err); self_name[self_name_len] = 0; ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); @@ -197,9 +203,6 @@ static void group_custom_packet_handler(Tox *tox, const Tox_Event_Group_Custom_P printf("%s sent custom packet to %s: %s\n", peer_name, self_name, message_buf); ck_assert(memcmp(message_buf, TEST_CUSTOM_PACKET, length) == 0); - AutoTox *autotox = (AutoTox *)user_data; - ck_assert(autotox != nullptr); - State *state = (State *)autotox->state; ++state->custom_packets_received; @@ -207,6 +210,9 @@ static void group_custom_packet_handler(Tox *tox, const Tox_Event_Group_Custom_P static void group_custom_packet_large_handler(Tox *tox, const Tox_Event_Group_Custom_Packet *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint8_t *data = tox_event_group_custom_packet_get_data(event); const size_t length = tox_event_group_custom_packet_get_data_length(event); @@ -214,9 +220,6 @@ static void group_custom_packet_large_handler(Tox *tox, const Tox_Event_Group_Cu ck_assert(memcmp(data, TEST_CUSTOM_PACKET_LARGE, length) == 0); - AutoTox *autotox = (AutoTox *)user_data; - ck_assert(autotox != nullptr); - State *state = (State *)autotox->state; ++state->custom_packets_received; @@ -224,6 +227,9 @@ static void group_custom_packet_large_handler(Tox *tox, const Tox_Event_Group_Cu static void group_message_handler(Tox *tox, const Tox_Event_Group_Message *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_message_get_group_number(event); const uint32_t peer_id = tox_event_group_message_get_peer_id(event); const uint8_t *message = tox_event_group_message_get_message(event); @@ -238,25 +244,25 @@ static void group_message_handler(Tox *tox, const Tox_Event_Group_Message *event message_buf[length] = 0; Tox_Err_Group_Peer_Query q_err; - size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); char peer_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err); + tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &q_err); peer_name[peer_name_len] = 0; ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); Tox_Err_Group_Self_Query s_err; - size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); + size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); char self_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err); + tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err); self_name[self_name_len] = 0; ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); @@ -265,9 +271,6 @@ static void group_message_handler(Tox *tox, const Tox_Event_Group_Message *event printf("%s sent message to %s:(id:%u) %s\n", peer_name, self_name, pseudo_msg_id, message_buf); ck_assert(memcmp(message_buf, TEST_MESSAGE, length) == 0); - AutoTox *autotox = (AutoTox *)user_data; - ck_assert(autotox != nullptr); - State *state = (State *)autotox->state; state->message_received = true; @@ -277,6 +280,9 @@ static void group_message_handler(Tox *tox, const Tox_Event_Group_Message *event static void group_private_message_handler(Tox *tox, const Tox_Event_Group_Private_Message *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_private_message_get_group_number(event); const uint32_t peer_id = tox_event_group_private_message_get_peer_id(event); const Tox_Message_Type type = tox_event_group_private_message_get_type(event); @@ -290,25 +296,25 @@ static void group_private_message_handler(Tox *tox, const Tox_Event_Group_Privat message_buf[length] = 0; Tox_Err_Group_Peer_Query q_err; - size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); char peer_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err); + tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &q_err); peer_name[peer_name_len] = 0; ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); Tox_Err_Group_Self_Query s_err; - size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); + size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); char self_name[TOX_MAX_NAME_LENGTH + 1]; - tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err); + tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err); self_name[self_name_len] = 0; ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); @@ -319,9 +325,6 @@ static void group_private_message_handler(Tox *tox, const Tox_Event_Group_Privat ck_assert(type == TOX_MESSAGE_TYPE_ACTION); - AutoTox *autotox = (AutoTox *)user_data; - ck_assert(autotox != nullptr); - State *state = (State *)autotox->state; state->private_message_received = true; diff --git a/auto_tests/group_moderation_test.c b/auto_tests/group_moderation_test.c index 7cb6d36a86..dcfb89320c 100644 --- a/auto_tests/group_moderation_test.c +++ b/auto_tests/group_moderation_test.c @@ -176,12 +176,12 @@ static void group_peer_join_handler(Tox *tox, const Tox_Event_Group_Peer_Join *e char peer_name[TOX_MAX_NAME_LENGTH + 1]; Tox_Err_Group_Peer_Query q_err; - size_t peer_name_len = tox_group_peer_get_name_size(tox, group_number, peer_id, &q_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, group_number, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); - tox_group_peer_get_name(tox, group_number, peer_id, (uint8_t *) peer_name, &q_err); + tox_group_peer_get_name(autotox->tox, group_number, peer_id, (uint8_t *) peer_name, &q_err); peer_name[peer_name_len] = 0; ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -262,7 +262,7 @@ static void group_mod_event_handler(Tox *tox, const Tox_Event_Group_Moderation * char peer_name[TOX_MAX_NAME_LENGTH + 1]; Tox_Err_Group_Peer_Query q_err; - size_t peer_name_len = tox_group_peer_get_name_size(tox, group_number, target_peer_id, &q_err); + size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, group_number, target_peer_id, &q_err); if (q_err == TOX_ERR_GROUP_PEER_QUERY_PEER_NOT_FOUND) { // may occurr on sync attempts return; @@ -271,11 +271,11 @@ static void group_mod_event_handler(Tox *tox, const Tox_Event_Group_Moderation * ck_assert_msg(q_err == TOX_ERR_GROUP_PEER_QUERY_OK, "error %d", q_err); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); - tox_group_peer_get_name(tox, group_number, target_peer_id, (uint8_t *) peer_name, &q_err); + tox_group_peer_get_name(autotox->tox, group_number, target_peer_id, (uint8_t *) peer_name, &q_err); peer_name[peer_name_len] = 0; ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); - Tox_Group_Role role = tox_group_peer_get_role(tox, group_number, target_peer_id, &q_err); + Tox_Group_Role role = tox_group_peer_get_role(autotox->tox, group_number, target_peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(role <= TOX_GROUP_ROLE_OBSERVER); diff --git a/auto_tests/group_save_test.c b/auto_tests/group_save_test.c index 417c0d0b0b..ac124037ad 100644 --- a/auto_tests/group_save_test.c +++ b/auto_tests/group_save_test.c @@ -28,12 +28,15 @@ typedef struct State { static void group_invite_handler(Tox *tox, const Tox_Event_Group_Invite *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t friend_number = tox_event_group_invite_get_friend_number(event); const uint8_t *invite_data = tox_event_group_invite_get_invite_data(event); const size_t length = tox_event_group_invite_get_invite_data_length(event); Tox_Err_Group_Invite_Accept err_accept; - tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)"test2", 5, + tox_group_invite_accept(autotox->tox, friend_number, invite_data, length, (const uint8_t *)"test2", 5, nullptr, 0, &err_accept); ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK); diff --git a/auto_tests/group_state_test.c b/auto_tests/group_state_test.c index 866c10a553..ba58cbb1ef 100644 --- a/auto_tests/group_state_test.c +++ b/auto_tests/group_state_test.c @@ -63,11 +63,14 @@ static bool all_group_peers_connected(const AutoTox *autotoxes, uint32_t tox_cou static void group_topic_lock_handler(Tox *tox, const Tox_Event_Group_Topic_Lock *event, void *user_data) { + const AutoTox *autotox = (const AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_topic_lock_get_group_number(event); const Tox_Group_Topic_Lock topic_lock = tox_event_group_topic_lock_get_topic_lock(event); Tox_Err_Group_State_Queries err; - Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(tox, groupnumber, &err); + Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(autotox->tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(current_topic_lock == topic_lock, "topic locks don't match in callback: %d %d", @@ -77,11 +80,14 @@ static void group_topic_lock_handler(Tox *tox, const Tox_Event_Group_Topic_Lock static void group_voice_state_handler(Tox *tox, const Tox_Event_Group_Voice_State *event, void *user_data) { + const AutoTox *autotox = (const AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_voice_state_get_group_number(event); const Tox_Group_Voice_State voice_state = tox_event_group_voice_state_get_voice_state(event); Tox_Err_Group_State_Queries err; - Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &err); + Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(autotox->tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(current_voice_state == voice_state, "voice states don't match in callback: %d %d", @@ -91,11 +97,14 @@ static void group_voice_state_handler(Tox *tox, const Tox_Event_Group_Voice_Stat static void group_privacy_state_handler(Tox *tox, const Tox_Event_Group_Privacy_State *event, void *user_data) { + const AutoTox *autotox = (const AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_privacy_state_get_group_number(event); const Tox_Group_Privacy_State privacy_state = tox_event_group_privacy_state_get_privacy_state(event); Tox_Err_Group_State_Queries err; - Tox_Group_Privacy_State current_pstate = tox_group_get_privacy_state(tox, groupnumber, &err); + Tox_Group_Privacy_State current_pstate = tox_group_get_privacy_state(autotox->tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(current_pstate == privacy_state, "privacy states don't match in callback"); @@ -103,11 +112,14 @@ static void group_privacy_state_handler(Tox *tox, const Tox_Event_Group_Privacy_ static void group_peer_limit_handler(Tox *tox, const Tox_Event_Group_Peer_Limit *event, void *user_data) { + const AutoTox *autotox = (const AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_peer_limit_get_group_number(event); const uint32_t peer_limit = tox_event_group_peer_limit_get_peer_limit(event); Tox_Err_Group_State_Queries err; - uint32_t current_plimit = tox_group_get_peer_limit(tox, groupnumber, &err); + uint32_t current_plimit = tox_group_get_peer_limit(autotox->tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(peer_limit == current_plimit, @@ -117,18 +129,21 @@ static void group_peer_limit_handler(Tox *tox, const Tox_Event_Group_Peer_Limit static void group_password_handler(Tox *tox, const Tox_Event_Group_Password *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t groupnumber = tox_event_group_password_get_group_number(event); const uint8_t *password = tox_event_group_password_get_password(event); const size_t length = tox_event_group_password_get_password_length(event); Tox_Err_Group_State_Queries err; - size_t curr_pwlength = tox_group_get_password_size(tox, groupnumber, &err); + size_t curr_pwlength = tox_group_get_password_size(autotox->tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert(length == curr_pwlength); uint8_t current_password[TOX_GROUP_MAX_PASSWORD_SIZE]; - tox_group_get_password(tox, groupnumber, current_password, &err); + tox_group_get_password(autotox->tox, groupnumber, current_password, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(memcmp(current_password, password, length) == 0, diff --git a/auto_tests/group_tcp_test.c b/auto_tests/group_tcp_test.c index 919c604616..7ff5a16800 100644 --- a/auto_tests/group_tcp_test.c +++ b/auto_tests/group_tcp_test.c @@ -21,6 +21,9 @@ typedef struct State { static void group_invite_handler(Tox *tox, const Tox_Event_Group_Invite *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t friend_number = tox_event_group_invite_get_friend_number(event); const uint8_t *invite_data = tox_event_group_invite_get_invite_data(event); const size_t length = tox_event_group_invite_get_invite_data_length(event); @@ -28,7 +31,7 @@ static void group_invite_handler(Tox *tox, const Tox_Event_Group_Invite *event, printf("Accepting friend invite\n"); Tox_Err_Group_Invite_Accept err_accept; - tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)"test", 4, + tox_group_invite_accept(autotox->tox, friend_number, invite_data, length, (const uint8_t *)"test", 4, nullptr, 0, &err_accept); ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK); } diff --git a/auto_tests/group_topic_test.c b/auto_tests/group_topic_test.c index 7f7fe953c8..27ab790f85 100644 --- a/auto_tests/group_topic_test.c +++ b/auto_tests/group_topic_test.c @@ -70,6 +70,9 @@ static void group_peer_join_handler(Tox *tox, const Tox_Event_Group_Peer_Join *e static void group_topic_handler(Tox *tox, const Tox_Event_Group_Topic *event, void *user_data) { + AutoTox *autotox = (AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t group_number = tox_event_group_topic_get_group_number(event); //const uint32_t peer_id = tox_event_group_topic_get_peer_id(event); const uint8_t *topic = tox_event_group_topic_get_topic(event); @@ -79,10 +82,10 @@ static void group_topic_handler(Tox *tox, const Tox_Event_Group_Topic *event, vo Tox_Err_Group_State_Queries query_err; uint8_t topic2[TOX_GROUP_MAX_TOPIC_LENGTH]; - tox_group_get_topic(tox, group_number, topic2, &query_err); + tox_group_get_topic(autotox->tox, group_number, topic2, &query_err); ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK); - size_t topic_length_getter = tox_group_get_topic_size(tox, group_number, &query_err); + size_t topic_length_getter = tox_group_get_topic_size(autotox->tox, group_number, &query_err); ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(topic_length_getter == topic_length && memcmp(topic, topic2, topic_length) == 0, "topic differs in callback: %s, %s", topic, topic2); @@ -90,11 +93,14 @@ static void group_topic_handler(Tox *tox, const Tox_Event_Group_Topic *event, vo static void group_topic_lock_handler(Tox *tox, const Tox_Event_Group_Topic_Lock *event, void *user_data) { + const AutoTox *autotox = (const AutoTox *)user_data; + ck_assert(autotox != nullptr); + const uint32_t group_number = tox_event_group_topic_lock_get_group_number(event); const Tox_Group_Topic_Lock topic_lock = tox_event_group_topic_lock_get_topic_lock(event); Tox_Err_Group_State_Queries err; - Tox_Group_Topic_Lock current_lock = tox_group_get_topic_lock(tox, group_number, &err); + Tox_Group_Topic_Lock current_lock = tox_group_get_topic_lock(autotox->tox, group_number, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); ck_assert_msg(topic_lock == current_lock, "topic locks differ in callback"); diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c index b7f9bdff03..c8ddc5e1a4 100644 --- a/auto_tests/save_load_test.c +++ b/auto_tests/save_load_test.c @@ -34,12 +34,14 @@ static void accept_friend_request(Tox *m, const Tox_Event_Friend_Request *event, void *userdata) { + Tox *tox = (Tox *)userdata; + const uint8_t *public_key = tox_event_friend_request_get_public_key(event); const uint8_t *message = tox_event_friend_request_get_message(event); uint32_t message_length = tox_event_friend_request_get_message_length(event); if (message_length == 7 && memcmp("Gentoo", message, 7) == 0) { - tox_friend_add_norequest(m, public_key, nullptr); + tox_friend_add_norequest(tox, public_key, nullptr); } } @@ -208,14 +210,14 @@ static void test_few_clients(void) Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(tox1, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch1, events, tox1, nullptr); + tox_dispatch_invoke(dispatch1, events, tox1, tox1); tox_events_free(events); } { Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(tox2, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch2, events, tox2, nullptr); + tox_dispatch_invoke(dispatch2, events, tox2, tox2); tox_events_free(events); } tox_iterate(tox3, nullptr); @@ -259,14 +261,14 @@ static void test_few_clients(void) Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(tox1, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch1, events, tox1, nullptr); + tox_dispatch_invoke(dispatch1, events, tox1, tox1); tox_events_free(events); } { Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(tox2, true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch2, events, tox2, nullptr); + tox_dispatch_invoke(dispatch2, events, tox2, tox2); tox_events_free(events); } tox_iterate(tox3, nullptr); diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index 4822a6a765..123d8eda5f 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -26,20 +26,27 @@ #define TOX_LOCALHOST "127.0.0.1" #endif +typedef struct State { + uint32_t to_comp; + Tox *tox; +} State; + static bool enable_broken_tests = false; static void accept_friend_request(Tox *m, const Tox_Event_Friend_Request *event, void *userdata) { + State *state = (State *)userdata; + const uint8_t *public_key = tox_event_friend_request_get_public_key(event); const uint8_t *message = tox_event_friend_request_get_message(event); const uint32_t message_length = tox_event_friend_request_get_message_length(event); - if (*((uint32_t *)userdata) != 974536) { + if (state->to_comp != 974536) { return; } if (message_length == 7 && memcmp("Gentoo", message, 7) == 0) { - tox_friend_add_norequest(m, public_key, nullptr); + tox_friend_add_norequest(state->tox, public_key, nullptr); } } @@ -143,7 +150,8 @@ static void test_many_clients_tcp(void) Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(toxes[i], true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch, events, toxes[i], &to_comp); + State state = {to_comp, toxes[i]}; + tox_dispatch_invoke(dispatch, events, toxes[i], &state); tox_events_free(events); } @@ -254,7 +262,8 @@ static void test_many_clients_tcp_b(void) Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(toxes[i], true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch, events, toxes[i], &to_comp); + State state = {to_comp, toxes[i]}; + tox_dispatch_invoke(dispatch, events, toxes[i], &state); tox_events_free(events); } diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 491e4583c2..d6c0d65fa1 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -15,12 +15,14 @@ static void accept_friend_request(Tox *m, const Tox_Event_Friend_Request *event, void *userdata) { + Tox *tox = (Tox *)userdata; + const uint8_t *public_key = tox_event_friend_request_get_public_key(event); const uint8_t *message = tox_event_friend_request_get_message(event); const uint32_t message_length = tox_event_friend_request_get_message_length(event); if (message_length == 7 && memcmp("Gentoo", message, 7) == 0) { - tox_friend_add_norequest(m, public_key, nullptr); + tox_friend_add_norequest(tox, public_key, nullptr); } } @@ -123,7 +125,7 @@ static void test_many_clients(void) Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK; Tox_Events *events = tox_events_iterate(toxes[i], true, &err); ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK); - tox_dispatch_invoke(dispatch, events, toxes[i], nullptr); + tox_dispatch_invoke(dispatch, events, toxes[i], toxes[i]); tox_events_free(events); }