Squashed 'external/toxcore/c-toxcore/' changes from c9cdae001..9ed2fa80d
9ed2fa80d fix(toxav): remove extra copy of video frame on encode de30cf3ad docs: Add new file kinds, that should be useful to all clients. d5b5e879d fix(DHT): Correct node skipping logic timed out nodes. 30e71fe97 refactor: Generate event dispatch functions and add tox_events_dispatch. 8fdbb0b50 style: Format parameter lists in event handlers. d00dee12b refactor: Add warning logs when losing chat invites. b144e8db1 feat: Add a way to look up a file number by ID. 849281ea0 feat: Add a way to fetch groups by chat ID. a2c177396 refactor: Harden event system and improve type safety. 8f5caa656 refactor: Add MessagePack string support to bin_pack. 34e8d5ad5 chore: Add GitHub CodeQL workflow and local Docker runner. f7b068010 refactor: Add nullability annotations to event headers. 788abe651 refactor(toxav): Use system allocator for mutexes. 2e4b423eb refactor: Use specific typedefs for public API arrays. 2baf34775 docs(toxav): update idle iteration interval see 679444751876fa3882a717772918ebdc8f083354 2f87ac67b feat: Add Event Loop abstraction (Ev). f8dfc38d8 test: Fix data race in ToxScenario virtual_clock. 38313921e test(TCP): Add regression test for TCP priority queue integrity. f94a50d9a refactor(toxav): Replace mutable_mutex with dynamically allocated mutex. ad054511e refactor: Internalize DHT structs and add debug helpers. 8b467cc96 fix: Prevent potential integer overflow in group chat handshake. 4962bdbb8 test: Improve TCP simulation and add tests 5f0227093 refactor: Allow nullable data in group chat handlers. e97b18ea9 chore: Improve Windows Docker support. b14943bbd refactor: Move Logger out of Messenger into Tox. dd3136250 cleanup: Apply nullability qualifiers to C++ codebase. 1849f70fc refactor: Extract low-level networking code to net and os_network. 8fec75421 refactor: Delete tox_random, align on rng and os_random. a03ae8051 refactor: Delete tox_memory, align on mem and os_memory. 4c88fed2c refactor: Use `std::` prefixes more consistently in C++ code. 72452f2ae test: Add some more tests for onion and shared key cache. d5a51b09a cleanup: Use tox_attributes.h in tox_private.h and install it. b6f5b9fc5 test: Add some benchmarks for various high level things. 8a8d02785 test(support): Introduce threaded Tox runner and simulation barrier d68d1d095 perf(toxav): optimize audio and video intermediate buffers by keeping them around REVERT: c9cdae001 fix(toxav): remove extra copy of video frame on encode git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 9ed2fa80d582c714d6bdde6a7648220a92cddff8
This commit is contained in:
@@ -6,16 +6,19 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "../toxcore/attributes.h"
|
||||
#include "../toxcore/logger.h"
|
||||
#include "../toxcore/os_memory.h"
|
||||
|
||||
namespace {
|
||||
|
||||
struct MockMsi {
|
||||
std::vector<std::vector<uint8_t>> sent_packets;
|
||||
std::vector<uint32_t> sent_to_friends;
|
||||
std::vector<std::vector<std::uint8_t>> sent_packets;
|
||||
std::vector<std::uint32_t> sent_to_friends;
|
||||
|
||||
struct CallbackStats {
|
||||
int invite = 0;
|
||||
@@ -26,11 +29,11 @@ struct MockMsi {
|
||||
int capabilities = 0;
|
||||
} stats;
|
||||
|
||||
MSICall *last_call = nullptr;
|
||||
MSICall *_Nullable last_call = nullptr;
|
||||
MSIError last_error = MSI_E_NONE;
|
||||
|
||||
static int send_packet(
|
||||
void *user_data, uint32_t friend_number, const uint8_t *data, size_t length)
|
||||
static int send_packet(void *_Nullable user_data, std::uint32_t friend_number,
|
||||
const std::uint8_t *_Nonnull data, std::size_t length)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(user_data);
|
||||
self->sent_packets.emplace_back(data, data + length);
|
||||
@@ -38,7 +41,7 @@ struct MockMsi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_invite(void *object, MSICall *call)
|
||||
static int on_invite(void *_Nullable object, MSICall *_Nonnull call)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(object);
|
||||
self->stats.invite++;
|
||||
@@ -46,7 +49,7 @@ struct MockMsi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_start(void *object, MSICall *call)
|
||||
static int on_start(void *_Nullable object, MSICall *_Nonnull call)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(object);
|
||||
self->stats.start++;
|
||||
@@ -54,7 +57,7 @@ struct MockMsi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_end(void *object, MSICall *call)
|
||||
static int on_end(void *_Nullable object, MSICall *_Nonnull call)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(object);
|
||||
self->stats.end++;
|
||||
@@ -62,7 +65,7 @@ struct MockMsi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_error(void *object, MSICall *call)
|
||||
static int on_error(void *_Nullable object, MSICall *_Nonnull call)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(object);
|
||||
self->stats.error++;
|
||||
@@ -71,7 +74,7 @@ struct MockMsi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_peertimeout(void *object, MSICall *call)
|
||||
static int on_peertimeout(void *_Nullable object, MSICall *_Nonnull call)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(object);
|
||||
self->stats.peertimeout++;
|
||||
@@ -79,7 +82,7 @@ struct MockMsi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_capabilities(void *object, MSICall *call)
|
||||
static int on_capabilities(void *_Nullable object, MSICall *_Nonnull call)
|
||||
{
|
||||
auto *self = static_cast<MockMsi *>(object);
|
||||
self->stats.capabilities++;
|
||||
@@ -92,7 +95,7 @@ class MsiTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
const Memory *mem = os_memory();
|
||||
const Memory *_Nonnull mem = os_memory();
|
||||
log = logger_new(mem);
|
||||
|
||||
MSICallbacks callbacks = {MockMsi::on_invite, MockMsi::on_start, MockMsi::on_end,
|
||||
@@ -109,8 +112,8 @@ protected:
|
||||
logger_kill(log);
|
||||
}
|
||||
|
||||
Logger *log;
|
||||
MSISession *session = nullptr;
|
||||
Logger *_Nullable log;
|
||||
MSISession *_Nullable session = nullptr;
|
||||
MockMsi mock;
|
||||
};
|
||||
|
||||
@@ -122,8 +125,8 @@ TEST_F(MsiTest, BasicNewKill)
|
||||
TEST_F(MsiTest, Invite)
|
||||
{
|
||||
MSICall *call = nullptr;
|
||||
uint32_t friend_number = 123;
|
||||
uint8_t capabilities = MSI_CAP_S_AUDIO | MSI_CAP_R_AUDIO;
|
||||
std::uint32_t friend_number = 123;
|
||||
std::uint8_t capabilities = MSI_CAP_S_AUDIO | MSI_CAP_R_AUDIO;
|
||||
|
||||
int rc = msi_invite(log, session, &call, friend_number, capabilities);
|
||||
ASSERT_EQ(rc, 0);
|
||||
@@ -146,11 +149,11 @@ TEST_F(MsiTest, Invite)
|
||||
|
||||
TEST_F(MsiTest, HandleIncomingInvite)
|
||||
{
|
||||
uint32_t friend_number = 456;
|
||||
uint8_t peer_caps = MSI_CAP_S_VIDEO | MSI_CAP_R_VIDEO;
|
||||
std::uint32_t friend_number = 456;
|
||||
std::uint8_t peer_caps = MSI_CAP_S_VIDEO | MSI_CAP_R_VIDEO;
|
||||
|
||||
// Craft invite packet
|
||||
uint8_t invite_pkt[] = {
|
||||
std::uint8_t invite_pkt[] = {
|
||||
1, 1, 0, // ID_REQUEST, len 1, REQU_INIT
|
||||
3, 1, peer_caps, // ID_CAPABILITIES, len 1, caps
|
||||
0 // end
|
||||
@@ -168,14 +171,14 @@ TEST_F(MsiTest, HandleIncomingInvite)
|
||||
TEST_F(MsiTest, Answer)
|
||||
{
|
||||
// 1. Receive invite first
|
||||
uint32_t friend_number = 456;
|
||||
uint8_t peer_caps = MSI_CAP_S_VIDEO | MSI_CAP_R_VIDEO;
|
||||
uint8_t invite_pkt[] = {1, 1, 0, 3, 1, peer_caps, 0};
|
||||
std::uint32_t friend_number = 456;
|
||||
std::uint8_t peer_caps = MSI_CAP_S_VIDEO | MSI_CAP_R_VIDEO;
|
||||
std::uint8_t invite_pkt[] = {1, 1, 0, 3, 1, peer_caps, 0};
|
||||
msi_handle_packet(session, log, friend_number, invite_pkt, sizeof(invite_pkt));
|
||||
MSICall *call = mock.last_call;
|
||||
|
||||
// 2. Answer it
|
||||
uint8_t my_caps = MSI_CAP_S_AUDIO | MSI_CAP_R_AUDIO;
|
||||
std::uint8_t my_caps = MSI_CAP_S_AUDIO | MSI_CAP_R_AUDIO;
|
||||
int rc = msi_answer(log, call, my_caps);
|
||||
ASSERT_EQ(rc, 0);
|
||||
EXPECT_EQ(call->state, MSI_CALL_ACTIVE);
|
||||
@@ -206,14 +209,14 @@ TEST_F(MsiTest, Hangup)
|
||||
TEST_F(MsiTest, ChangeCapabilities)
|
||||
{
|
||||
// Setup active call
|
||||
uint32_t friend_number = 123;
|
||||
uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
std::uint32_t friend_number = 123;
|
||||
std::uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, invite_pkt, sizeof(invite_pkt));
|
||||
MSICall *call = mock.last_call;
|
||||
msi_answer(log, call, 0);
|
||||
mock.sent_packets.clear();
|
||||
|
||||
uint8_t new_caps = MSI_CAP_S_VIDEO;
|
||||
std::uint8_t new_caps = MSI_CAP_S_VIDEO;
|
||||
int rc = msi_change_capabilities(log, call, new_caps);
|
||||
ASSERT_EQ(rc, 0);
|
||||
EXPECT_EQ(call->self_capabilities, new_caps);
|
||||
@@ -226,7 +229,7 @@ TEST_F(MsiTest, ChangeCapabilities)
|
||||
TEST_F(MsiTest, PeerTimeout)
|
||||
{
|
||||
MSICall *call = nullptr;
|
||||
uint32_t friend_number = 123;
|
||||
std::uint32_t friend_number = 123;
|
||||
msi_invite(log, session, &call, friend_number, 0);
|
||||
|
||||
msi_call_timeout(session, log, friend_number);
|
||||
@@ -236,12 +239,12 @@ TEST_F(MsiTest, PeerTimeout)
|
||||
|
||||
TEST_F(MsiTest, RemoteHangup)
|
||||
{
|
||||
uint32_t friend_number = 123;
|
||||
std::uint32_t friend_number = 123;
|
||||
MSICall *call = nullptr;
|
||||
msi_invite(log, session, &call, friend_number, 0);
|
||||
|
||||
// Craft pop packet
|
||||
uint8_t pop_pkt[] = {1, 1, 2, 0}; // REQU_POP
|
||||
std::uint8_t pop_pkt[] = {1, 1, 2, 0}; // REQU_POP
|
||||
msi_handle_packet(session, log, friend_number, pop_pkt, sizeof(pop_pkt));
|
||||
|
||||
EXPECT_EQ(mock.stats.end, 1);
|
||||
@@ -249,12 +252,12 @@ TEST_F(MsiTest, RemoteHangup)
|
||||
|
||||
TEST_F(MsiTest, RemoteError)
|
||||
{
|
||||
uint32_t friend_number = 123;
|
||||
std::uint32_t friend_number = 123;
|
||||
MSICall *call = nullptr;
|
||||
msi_invite(log, session, &call, friend_number, 0);
|
||||
|
||||
// Craft error packet (ID_ERROR = 2)
|
||||
uint8_t error_pkt[] = {1, 1, 2, 2, 1, 1, 0}; // REQU_POP + MSI_E_INVALID_MESSAGE
|
||||
std::uint8_t error_pkt[] = {1, 1, 2, 2, 1, 1, 0}; // REQU_POP + MSI_E_INVALID_MESSAGE
|
||||
msi_handle_packet(session, log, friend_number, error_pkt, sizeof(error_pkt));
|
||||
|
||||
EXPECT_EQ(mock.stats.error, 1);
|
||||
@@ -278,7 +281,7 @@ TEST_F(MsiTest, MultipleConcurrentCalls)
|
||||
msi_hangup(log, call1);
|
||||
|
||||
// Call 2 should still be there
|
||||
uint8_t pop_pkt[] = {1, 1, 2, 0};
|
||||
std::uint8_t pop_pkt[] = {1, 1, 2, 0};
|
||||
msi_handle_packet(session, log, 2, pop_pkt, sizeof(pop_pkt));
|
||||
EXPECT_EQ(mock.stats.end, 1);
|
||||
}
|
||||
@@ -288,8 +291,8 @@ TEST_F(MsiTest, RemoteAnswer)
|
||||
MSICall *call = nullptr;
|
||||
msi_invite(log, session, &call, 123, 0);
|
||||
|
||||
uint8_t peer_caps = MSI_CAP_S_AUDIO;
|
||||
uint8_t push_pkt[] = {1, 1, 1, 3, 1, peer_caps, 0}; // REQU_PUSH + capabilities
|
||||
std::uint8_t peer_caps = MSI_CAP_S_AUDIO;
|
||||
std::uint8_t push_pkt[] = {1, 1, 1, 3, 1, peer_caps, 0}; // REQU_PUSH + capabilities
|
||||
msi_handle_packet(session, log, 123, push_pkt, sizeof(push_pkt));
|
||||
|
||||
EXPECT_EQ(mock.stats.start, 1);
|
||||
@@ -299,14 +302,14 @@ TEST_F(MsiTest, RemoteAnswer)
|
||||
|
||||
TEST_F(MsiTest, RemoteCapabilitiesChange)
|
||||
{
|
||||
uint32_t friend_number = 123;
|
||||
uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
std::uint32_t friend_number = 123;
|
||||
std::uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, invite_pkt, sizeof(invite_pkt));
|
||||
MSICall *call = mock.last_call;
|
||||
msi_answer(log, call, 0);
|
||||
|
||||
uint8_t new_caps = MSI_CAP_S_VIDEO;
|
||||
uint8_t push_pkt[] = {1, 1, 1, 3, 1, new_caps, 0}; // REQU_PUSH + new capabilities
|
||||
std::uint8_t new_caps = MSI_CAP_S_VIDEO;
|
||||
std::uint8_t push_pkt[] = {1, 1, 1, 3, 1, new_caps, 0}; // REQU_PUSH + new capabilities
|
||||
msi_handle_packet(session, log, friend_number, push_pkt, sizeof(push_pkt));
|
||||
|
||||
EXPECT_EQ(mock.stats.capabilities, 1);
|
||||
@@ -315,8 +318,8 @@ TEST_F(MsiTest, RemoteCapabilitiesChange)
|
||||
|
||||
TEST_F(MsiTest, FriendRecall)
|
||||
{
|
||||
uint32_t friend_number = 123;
|
||||
uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
std::uint32_t friend_number = 123;
|
||||
std::uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, invite_pkt, sizeof(invite_pkt));
|
||||
MSICall *call = mock.last_call;
|
||||
msi_answer(log, call, 0);
|
||||
@@ -348,30 +351,30 @@ TEST_F(MsiTest, GapInFriendNumbers)
|
||||
|
||||
TEST_F(MsiTest, InvalidPackets)
|
||||
{
|
||||
uint32_t friend_number = 123;
|
||||
std::uint32_t friend_number = 123;
|
||||
|
||||
// Empty packet
|
||||
uint8_t empty = 0;
|
||||
std::uint8_t empty = 0;
|
||||
msi_handle_packet(session, log, friend_number, &empty, 0);
|
||||
|
||||
// Missing end byte
|
||||
uint8_t no_end[] = {1, 1, 0};
|
||||
std::uint8_t no_end[] = {1, 1, 0};
|
||||
msi_handle_packet(session, log, friend_number, no_end, sizeof(no_end));
|
||||
|
||||
// Invalid ID
|
||||
uint8_t invalid_id[] = {99, 1, 0, 0};
|
||||
std::uint8_t invalid_id[] = {99, 1, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, invalid_id, sizeof(invalid_id));
|
||||
|
||||
// Invalid size (too large)
|
||||
uint8_t invalid_size[] = {1, 10, 0, 0};
|
||||
std::uint8_t invalid_size[] = {1, 10, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, invalid_size, sizeof(invalid_size));
|
||||
|
||||
// Invalid size (mismatch)
|
||||
uint8_t size_mismatch[] = {1, 2, 0, 0};
|
||||
std::uint8_t size_mismatch[] = {1, 2, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, size_mismatch, sizeof(size_mismatch));
|
||||
|
||||
// Missing request field
|
||||
uint8_t no_request[] = {3, 1, 0, 0};
|
||||
std::uint8_t no_request[] = {3, 1, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, no_request, sizeof(no_request));
|
||||
}
|
||||
|
||||
@@ -387,7 +390,7 @@ TEST_F(MsiTest, CallbackFailure)
|
||||
|
||||
MSISession *fail_session = msi_new(log, MockMsi::send_packet, &mock, &callbacks, &mock);
|
||||
|
||||
uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
std::uint8_t invite_pkt[] = {1, 1, 0, 3, 1, 0, 0};
|
||||
msi_handle_packet(fail_session, log, 123, invite_pkt, sizeof(invite_pkt));
|
||||
|
||||
// Should have sent an error back
|
||||
@@ -417,14 +420,14 @@ TEST_F(MsiTest, InvalidStates)
|
||||
|
||||
TEST_F(MsiTest, StrayPackets)
|
||||
{
|
||||
uint32_t friend_number = 123;
|
||||
std::uint32_t friend_number = 123;
|
||||
|
||||
// PUSH for non-existent call
|
||||
uint8_t push_pkt[] = {1, 1, 1, 3, 1, 0, 0};
|
||||
std::uint8_t push_pkt[] = {1, 1, 1, 3, 1, 0, 0};
|
||||
msi_handle_packet(session, log, friend_number, push_pkt, sizeof(push_pkt));
|
||||
|
||||
// POP for non-existent call
|
||||
uint8_t pop_pkt[] = {1, 1, 2, 0};
|
||||
std::uint8_t pop_pkt[] = {1, 1, 2, 0};
|
||||
msi_handle_packet(session, log, friend_number, pop_pkt, sizeof(pop_pkt));
|
||||
|
||||
// Error sent back for stray PUSH
|
||||
|
||||
Reference in New Issue
Block a user