Squashed 'external/toxcore/c-toxcore/' changes from 1828c5356..c9cdae001

c9cdae001 fix(toxav): remove extra copy of video frame on encode
4f6d4546b test: Improve the fake network library.
a2581e700 refactor(toxcore): generate `Friend_Request` and `Dht_Nodes_Response`
2aaa11770 refactor(toxcore): use Tox_Memory in generated events
5c367452b test(toxcore): fix incorrect mutex in tox_scenario_get_time
8f92e710f perf: Add a timed limit of number of cookie requests.
695b6417a test: Add some more simulated network support.
815ae9ce9 test(toxcore): fix thread-safety in scenario framework
6d85c754e test(toxcore): add unit tests for net_crypto
9c22e79cc test(support): add SimulatedEnvironment for deterministic testing
f34fcb195 chore: Update windows Dockerfile to debian stable (trixie).
ece0e8980 fix(group_moderation): allow validating unsorted sanction list signatures
a4fa754d7 refactor: rename struct Packet to struct Net_Packet
d6f330f85 cleanup: Fix some warnings from coverity.
e206bffa2 fix(group_chats): fix sync packets reverting topics
0e4715598 test: Add new scenario testing framework.
668291f44 refactor(toxcore): decouple Network_Funcs from sockaddr via IP_Port
fc4396cef fix: potential division by zero in toxav and unsafe hex parsing
8e8b352ab refactor: Add nullable annotations to struct members.
7740bb421 refactor: decouple net_crypto from DHT
1936d4296 test: add benchmark for toxav audio and video
46bfdc2df fix: correct printf format specifiers for unsigned integers
REVERT: 1828c5356 fix(toxav): remove extra copy of video frame on encode

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: c9cdae001341e701fca980c9bb9febfeb95d2902
This commit is contained in:
Green Sky
2026-01-11 14:42:31 +01:00
parent e95f2cbb1c
commit 565efa4f39
328 changed files with 19057 additions and 13982 deletions

View File

@@ -1,4 +1,7 @@
// clang-format off
#include "../testing/support/public/simulated_environment.hh"
#include "group_moderation.h"
// clang-format on
#include <gtest/gtest.h>
@@ -10,17 +13,18 @@
#include "crypto_core.h"
#include "crypto_core_test_util.hh"
#include "logger.h"
#include "mem_test_util.hh"
#include "util.h"
namespace {
using tox::test::SimulatedEnvironment;
using ModerationHash = std::array<uint8_t, MOD_MODERATION_HASH_SIZE>;
TEST(ModList, PackedSizeOfEmptyModListIsZero)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
EXPECT_EQ(mod_list_packed_size(&mods), 0);
uint8_t byte = 1;
@@ -30,16 +34,18 @@ TEST(ModList, PackedSizeOfEmptyModListIsZero)
TEST(ModList, UnpackingZeroSizeArrayIsNoop)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
const uint8_t byte = 1;
EXPECT_EQ(mod_list_unpack(&mods, &byte, 0, 0), 0);
}
TEST(ModList, AddRemoveMultipleMods)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
uint8_t sig_pk1[32] = {1};
uint8_t sig_pk2[32] = {2};
EXPECT_TRUE(mod_list_add_entry(&mods, sig_pk1));
@@ -51,8 +57,9 @@ TEST(ModList, AddRemoveMultipleMods)
TEST(ModList, PackingAndUnpackingList)
{
using ModListEntry = std::array<uint8_t, MOD_LIST_ENTRY_SIZE>;
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
EXPECT_TRUE(mod_list_add_entry(&mods, ModListEntry{}.data()));
std::vector<uint8_t> packed(mod_list_packed_size(&mods));
@@ -60,7 +67,7 @@ TEST(ModList, PackingAndUnpackingList)
EXPECT_TRUE(mod_list_remove_entry(&mods, ModListEntry{}.data()));
Moderation mods2{mem};
Moderation mods2{&c_mem};
EXPECT_EQ(mod_list_unpack(&mods2, packed.data(), packed.size(), 1), packed.size());
EXPECT_TRUE(mod_list_remove_entry(&mods2, ModListEntry{}.data()));
}
@@ -68,14 +75,15 @@ TEST(ModList, PackingAndUnpackingList)
TEST(ModList, UnpackingTooManyModsFails)
{
using ModListEntry = std::array<uint8_t, MOD_LIST_ENTRY_SIZE>;
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
EXPECT_TRUE(mod_list_add_entry(&mods, ModListEntry{}.data()));
std::vector<uint8_t> packed(mod_list_packed_size(&mods));
mod_list_pack(&mods, packed.data());
Moderation mods2{mem};
Moderation mods2{&c_mem};
EXPECT_EQ(mod_list_unpack(&mods2, packed.data(), packed.size(), 2), -1);
EXPECT_TRUE(mod_list_remove_entry(&mods, ModListEntry{}.data()));
}
@@ -84,45 +92,50 @@ TEST(ModList, UnpackingFromEmptyBufferFails)
{
std::vector<uint8_t> packed(1);
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
EXPECT_EQ(mod_list_unpack(&mods, packed.data(), 0, 1), -1);
}
TEST(ModList, HashOfEmptyModListZeroesOutBuffer)
{
Test_Memory mem;
Test_Random rng;
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
auto c_rng = env.fake_random().get_c_random();
Moderation mods{mem};
Moderation mods{&c_mem};
// Fill with random data, check that it's zeroed.
ModerationHash hash;
random_bytes(rng, hash.data(), hash.size());
random_bytes(&c_rng, hash.data(), hash.size());
EXPECT_TRUE(mod_list_make_hash(&mods, hash.data()));
EXPECT_EQ(hash, ModerationHash{});
}
TEST(ModList, RemoveIndexFromEmptyModListFails)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
EXPECT_FALSE(mod_list_remove_index(&mods, 0));
EXPECT_FALSE(mod_list_remove_index(&mods, UINT16_MAX));
}
TEST(ModList, RemoveEntryFromEmptyModListFails)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
uint8_t sig_pk[32] = {0};
EXPECT_FALSE(mod_list_remove_entry(&mods, sig_pk));
}
TEST(ModList, ModListRemoveIndex)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
uint8_t sig_pk[32] = {1};
EXPECT_TRUE(mod_list_add_entry(&mods, sig_pk));
EXPECT_TRUE(mod_list_remove_index(&mods, 0));
@@ -130,23 +143,26 @@ TEST(ModList, ModListRemoveIndex)
TEST(ModList, CleanupOnEmptyModsIsNoop)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
mod_list_cleanup(&mods);
}
TEST(ModList, EmptyModListCannotVerifyAnySigPk)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
uint8_t sig_pk[32] = {1};
EXPECT_FALSE(mod_list_verify_sig_pk(&mods, sig_pk));
}
TEST(ModList, ModListAddVerifyRemoveSigPK)
{
Test_Memory mem;
Moderation mods{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods{&c_mem};
uint8_t sig_pk[32] = {1};
EXPECT_TRUE(mod_list_add_entry(&mods, sig_pk));
EXPECT_TRUE(mod_list_verify_sig_pk(&mods, sig_pk));
@@ -156,8 +172,9 @@ TEST(ModList, ModListAddVerifyRemoveSigPK)
TEST(ModList, ModListHashCheck)
{
Test_Memory mem;
Moderation mods1{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mods1{&c_mem};
uint8_t sig_pk1[32] = {1};
std::array<uint8_t, MOD_MODERATION_HASH_SIZE> hash1;
@@ -179,8 +196,9 @@ TEST(SanctionsList, PackingIntoUndersizedBufferFails)
TEST(SanctionsList, PackUnpackSanctionsCreds)
{
Test_Memory mem;
Moderation mod{mem};
SimulatedEnvironment env;
auto c_mem = env.fake_memory().get_c_memory();
Moderation mod{&c_mem};
std::array<uint8_t, MOD_SANCTIONS_CREDS_SIZE> packed;
EXPECT_EQ(sanctions_creds_pack(&mod.sanctions_creds, packed.data()), MOD_SANCTIONS_CREDS_SIZE);
EXPECT_EQ(
@@ -189,20 +207,30 @@ TEST(SanctionsList, PackUnpackSanctionsCreds)
struct SanctionsListMod : ::testing::Test {
protected:
SimulatedEnvironment env;
Tox_Memory c_mem_;
Tox_Random c_rng_;
Extended_Public_Key pk;
Extended_Secret_Key sk;
Test_Random rng;
Test_Memory mem;
Logger *log = logger_new(mem);
Moderation mod{mem};
Logger *log = nullptr;
Moderation mod;
Mod_Sanction sanctions[2] = {};
const uint8_t sanctioned_pk1[32] = {1};
const uint8_t sanctioned_pk2[32] = {2};
SanctionsListMod()
: c_mem_(env.fake_memory().get_c_memory())
, c_rng_(env.fake_random().get_c_random())
, mod{&c_mem_}
{
}
void SetUp() override
{
ASSERT_TRUE(create_extended_keypair(&pk, &sk, rng));
log = logger_new(&c_mem_);
ASSERT_TRUE(create_extended_keypair(&pk, &sk, &c_rng_));
mod.log = log;