adopt to new toxcore master

This commit is contained in:
Green Sky 2024-03-08 10:50:58 +01:00
parent 6ec6fe96e4
commit a8d8613f2c
No known key found for this signature in database
5 changed files with 8 additions and 145 deletions

@ -1 +1 @@
Subproject commit eeb57e137d08798bb08dc8de1f69abcabf0e0611 Subproject commit 4bd7235a739dec020365d216509474f641029113

@ -1 +1 @@
Subproject commit fa4298d790b2a2adf19435239b96664cc40a09a8 Subproject commit 49ab40a1ba97e884bf43ab5f35cfb48fc51f91de

View File

@ -19,6 +19,8 @@ add_library(toxcore STATIC
${TOX_DIR}toxcore/ccompat.h ${TOX_DIR}toxcore/ccompat.h
${TOX_DIR}toxcore/crypto_core.c ${TOX_DIR}toxcore/crypto_core.c
${TOX_DIR}toxcore/crypto_core.h ${TOX_DIR}toxcore/crypto_core.h
${TOX_DIR}toxcore/crypto_core_pack.c
${TOX_DIR}toxcore/crypto_core_pack.h
${TOX_DIR}toxcore/DHT.c ${TOX_DIR}toxcore/DHT.c
${TOX_DIR}toxcore/DHT.h ${TOX_DIR}toxcore/DHT.h
${TOX_DIR}toxcore/events/conference_connected.c ${TOX_DIR}toxcore/events/conference_connected.c
@ -27,6 +29,7 @@ add_library(toxcore STATIC
${TOX_DIR}toxcore/events/conference_peer_list_changed.c ${TOX_DIR}toxcore/events/conference_peer_list_changed.c
${TOX_DIR}toxcore/events/conference_peer_name.c ${TOX_DIR}toxcore/events/conference_peer_name.c
${TOX_DIR}toxcore/events/conference_title.c ${TOX_DIR}toxcore/events/conference_title.c
${TOX_DIR}toxcore/events/dht_get_nodes_response.c
${TOX_DIR}toxcore/events/events_alloc.c ${TOX_DIR}toxcore/events/events_alloc.c
${TOX_DIR}toxcore/events/events_alloc.h ${TOX_DIR}toxcore/events/events_alloc.h
${TOX_DIR}toxcore/events/file_chunk_request.c ${TOX_DIR}toxcore/events/file_chunk_request.c
@ -209,8 +212,3 @@ add_executable(DHT_Bootstrap EXCLUDE_FROM_ALL
) )
target_link_libraries(DHT_Bootstrap toxcore) target_link_libraries(DHT_Bootstrap toxcore)
add_executable(mono_time_test
./mono_time_test.cc
)
target_link_libraries(mono_time_test toxcore)
target_compile_features(mono_time_test PUBLIC cxx_std_11)

View File

@ -1,138 +0,0 @@
#include "./c-toxcore/toxcore/mono_time.h"
#ifdef NDEBUG
#undef NDEBUG
#include <cassert>
#else
#include <cassert>
#endif
#include <iostream>
#include <thread>
#include <chrono>
#define TEST(x, y) bool run_test_##x##y(void)
#define ASSERT_NE(x, y) assert((x) != (y))
#define EXPECT_GT(x, y) assert((x) > (y))
#define EXPECT_FALSE(x) assert(!(x))
#define EXPECT_TRUE(x) assert((x))
#define EXPECT_EQ(x, y) assert((x) == (y))
TEST(MonoTime, UnixTimeIncreasesOverTime)
{
const Memory *mem = system_memory();
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ASSERT_NE(mono_time, nullptr);
mono_time_update(mono_time);
uint64_t const start = mono_time_get(mono_time);
while (start == mono_time_get(mono_time)) {
mono_time_update(mono_time);
}
uint64_t const end = mono_time_get(mono_time);
EXPECT_GT(end, start);
mono_time_free(mem, mono_time);
return true;
}
TEST(MonoTime, IsTimeout)
{
const Memory *mem = system_memory();
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ASSERT_NE(mono_time, nullptr);
uint64_t const start = mono_time_get(mono_time);
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 1));
while (start == mono_time_get(mono_time)) {
mono_time_update(mono_time);
}
EXPECT_TRUE(mono_time_is_timeout(mono_time, start, 1));
mono_time_free(mem, mono_time);
return true;
}
TEST(MonoTime, IsTimeoutReal)
{
const Memory *mem = system_memory();
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ASSERT_NE(mono_time, nullptr);
uint64_t const start = mono_time_get(mono_time);
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
mono_time_update(mono_time);
// should still not have timed out (5sec) after sleeping ~20ms
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));
mono_time_free(mem, mono_time);
return true;
}
TEST(MonoTime, CustomTime)
{
const Memory *mem = system_memory();
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ASSERT_NE(mono_time, nullptr);
uint64_t test_time = current_time_monotonic(mono_time) + 42137;
mono_time_set_current_time_callback(
mono_time, [](void *user_data) { return *static_cast<uint64_t *>(user_data); }, &test_time);
mono_time_update(mono_time);
EXPECT_EQ(current_time_monotonic(mono_time), test_time);
uint64_t const start = mono_time_get(mono_time);
test_time += 7000;
mono_time_update(mono_time);
EXPECT_EQ(mono_time_get(mono_time) - start, 7);
EXPECT_EQ(current_time_monotonic(mono_time), test_time);
mono_time_free(mem, mono_time);
return true;
}
int main(int argc, char **argv) {
if (!run_test_MonoTimeUnixTimeIncreasesOverTime()) {
std::cerr << "MonoTimeUnixTimeIncreasesOverTime() failed\n";
return -1;
}
std::cerr << "MonoTimeUnixTimeIncreasesOverTime() succeeded\n";
if (!run_test_MonoTimeIsTimeout()) {
std::cerr << "MonoTimeIsTimeout() failed\n";
return -1;
}
std::cerr << "MonoTimeIsTimeout() succeeded\n";
if (!run_test_MonoTimeIsTimeoutReal()) {
std::cerr << "MonoTimeIsTimeoutReal() failed\n";
return -1;
}
std::cerr << "MonoTimeIsTimeoutReal() succeeded\n";
if (!run_test_MonoTimeCustomTime()) {
std::cerr << "MonoTimeCustomTime() failed\n";
return -1;
}
std::cerr << "MonoTimeCustomTime() succeeded\n";
return 0;
}

View File

@ -1,4 +1,5 @@
#include "./tox_client.hpp" #include "./tox_client.hpp"
#include "toxcore/tox.h"
// meh, change this // meh, change this
#include <exception> #include <exception>
@ -67,6 +68,8 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
} }
} }
tox_options_set_experimental_groups_persistence(options, true);
TOX_ERR_NEW err_new; TOX_ERR_NEW err_new;
_tox = tox_new(options, &err_new); _tox = tox_new(options, &err_new);
tox_options_free(options); tox_options_free(options);