2022-11-02 00:32:26 +00:00
|
|
|
// This file Copyright (C) 2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <cstdint> // int64_t
|
|
|
|
#include <memory>
|
|
|
|
#include <string_view>
|
|
|
|
|
2023-01-02 16:23:51 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <libtransmission/log.h>
|
|
|
|
#include <libtransmission/net.h>
|
2023-12-02 20:16:36 +00:00
|
|
|
#include <libtransmission/open-files.h>
|
2023-11-03 17:03:26 +00:00
|
|
|
#include <libtransmission/peer-io.h>
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <libtransmission/quark.h>
|
2024-02-15 17:31:09 +00:00
|
|
|
#include <libtransmission/session.h>
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2023-07-08 15:24:03 +00:00
|
|
|
#include "gtest/gtest.h"
|
2022-11-02 00:32:26 +00:00
|
|
|
|
|
|
|
using namespace std::literals;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
using SettingsTest = ::testing::Test;
|
2022-11-02 00:32:26 +00:00
|
|
|
|
|
|
|
TEST_F(SettingsTest, canInstantiate)
|
|
|
|
{
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2023-09-08 00:05:16 +00:00
|
|
|
EXPECT_TRUE(var.has_value());
|
2022-11-02 00:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadBools)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_seed_queue_enabled;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const expected_value = !settings.seed_queue_enabled;
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddBool(&var, Key, expected_value);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings.load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expected_value, settings.seed_queue_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveBools)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_seed_queue_enabled;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const expected_value = !settings.seed_queue_enabled;
|
|
|
|
settings.seed_queue_enabled = expected_value;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = bool{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindBool(&var, Key, &val));
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(expected_value, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadDoubles)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_ratio_limit;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const expected_value = settings.ratio_limit + 1.0;
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddReal(&var, Key, expected_value);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings.load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_NEAR(expected_value, settings.ratio_limit, 0.001);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveDoubles)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_seed_queue_enabled;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings.seed_queue_enabled;
|
|
|
|
auto const expected_value = !default_value;
|
|
|
|
settings.seed_queue_enabled = expected_value;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = bool{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindBool(&var, Key, &val));
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(expected_value, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadEncryptionMode)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_encryption;
|
|
|
|
static auto constexpr ExpectedValue = TR_ENCRYPTION_REQUIRED;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2022-11-02 00:32:26 +00:00
|
|
|
ASSERT_NE(ExpectedValue, settings->encryption_mode);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ExpectedValue);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->encryption_mode);
|
2023-08-21 04:15:23 +00:00
|
|
|
var.clear();
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-08-21 04:15:23 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "required");
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->encryption_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveEncryptionMode)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_encryption;
|
|
|
|
static auto constexpr ExpectedValue = TR_ENCRYPTION_REQUIRED;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_NE(ExpectedValue, settings.seed_queue_enabled);
|
|
|
|
settings.encryption_mode = ExpectedValue;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-26 13:32:51 +00:00
|
|
|
auto val = int64_t{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindInt(&var, Key, &val));
|
2022-11-26 13:32:51 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, val);
|
2022-11-02 00:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadLogLevel)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_message_level;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings->log_level;
|
|
|
|
auto constexpr ExpectedValue = TR_LOG_DEBUG;
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ExpectedValue);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->log_level);
|
2023-08-21 04:15:23 +00:00
|
|
|
var.clear();
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-08-21 04:15:23 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "debug");
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->log_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveLogLevel)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_message_level;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings.log_level;
|
|
|
|
auto constexpr ExpectedValue = TR_LOG_DEBUG;
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
settings.log_level = ExpectedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-26 13:32:51 +00:00
|
|
|
auto val = int64_t{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindInt(&var, Key, &val));
|
2022-11-26 13:32:51 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, val);
|
2022-11-02 00:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadMode)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_umask;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings->umask;
|
|
|
|
auto constexpr ExpectedValue = tr_mode_t{ 0777 };
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ExpectedValue);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->umask);
|
2023-08-21 04:15:23 +00:00
|
|
|
var.clear();
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-08-21 04:15:23 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "0777");
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->umask);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveMode)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_umask;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings.log_level;
|
|
|
|
auto constexpr ExpectedValue = tr_mode_t{ 0777 };
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
settings.umask = ExpectedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = std::string_view{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindStrView(&var, Key, &val));
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ("0777", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadPort)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_peer_port;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings.peer_port;
|
2023-08-18 03:13:01 +00:00
|
|
|
auto constexpr ExpectedValue = tr_port::from_host(8080);
|
2022-11-02 00:32:26 +00:00
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ExpectedValue.host());
|
2023-09-08 00:05:16 +00:00
|
|
|
settings.load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings.peer_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSavePort)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_peer_port;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings.peer_port;
|
2023-08-18 03:13:01 +00:00
|
|
|
auto constexpr ExpectedValue = tr_port::from_host(8080);
|
2022-11-02 00:32:26 +00:00
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
settings.peer_port = ExpectedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = int64_t{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindInt(&var, Key, &val));
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue.host(), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadPreallocation)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_preallocation;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings->preallocation_mode;
|
2023-12-02 20:16:36 +00:00
|
|
|
auto constexpr ExpectedValue = tr_open_files::Preallocation::Full;
|
2022-11-02 00:32:26 +00:00
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
2023-12-02 20:16:36 +00:00
|
|
|
tr_variantDictAddInt(&var, Key, static_cast<int64_t>(ExpectedValue));
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->preallocation_mode);
|
2023-08-21 04:15:23 +00:00
|
|
|
var.clear();
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-08-21 04:15:23 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "full");
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ExpectedValue, settings->preallocation_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSavePreallocation)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_preallocation;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings.preallocation_mode;
|
2023-12-02 20:16:36 +00:00
|
|
|
auto constexpr ExpectedValue = tr_open_files::Preallocation::Full;
|
2022-11-02 00:32:26 +00:00
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
settings.preallocation_mode = ExpectedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-26 13:32:51 +00:00
|
|
|
auto val = int64_t{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindInt(&var, Key, &val));
|
2023-12-02 20:16:36 +00:00
|
|
|
EXPECT_EQ(static_cast<int64_t>(ExpectedValue), val);
|
2022-11-02 00:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadSizeT)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_queue_stalled_minutes;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const expected_value = settings.queue_stalled_minutes + 5U;
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, expected_value);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings.load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(expected_value, settings.queue_stalled_minutes);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveSizeT)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_queue_stalled_minutes;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const expected_value = settings.queue_stalled_minutes + 5U;
|
|
|
|
|
|
|
|
settings.queue_stalled_minutes = expected_value;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = int64_t{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindInt(&var, Key, &val));
|
2022-11-17 00:03:48 +00:00
|
|
|
EXPECT_EQ(expected_value, static_cast<size_t>(val));
|
2022-11-02 00:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadString)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_bind_address_ipv4;
|
|
|
|
static auto constexpr ChangedValue = std::string_view{ "127.0.0.1" };
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
|
|
|
EXPECT_NE(ChangedValue, tr_session::Settings{}.bind_address_ipv4);
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, ChangedValue);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings.load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ChangedValue, settings.bind_address_ipv4);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveString)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_bind_address_ipv4;
|
|
|
|
static auto constexpr ChangedValue = std::string_view{ "127.0.0.1" };
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
|
|
|
EXPECT_NE(ChangedValue, tr_session::Settings{}.bind_address_ipv4);
|
2022-11-02 00:32:26 +00:00
|
|
|
|
|
|
|
settings.bind_address_ipv4 = ChangedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = std::string_view{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindStrView(&var, Key, &val));
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ChangedValue, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadTos)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_peer_socket_tos;
|
|
|
|
static auto constexpr ChangedValue = tr_tos_t{ 0x20 };
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto const default_value = settings->peer_socket_tos;
|
|
|
|
ASSERT_NE(ChangedValue, default_value);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, 0x20);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ChangedValue, settings->peer_socket_tos);
|
2023-08-21 04:15:23 +00:00
|
|
|
var.clear();
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-08-21 04:15:23 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "cs1");
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ChangedValue, settings->peer_socket_tos);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveTos)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_peer_socket_tos;
|
|
|
|
static auto constexpr ChangedValue = tr_tos_t{ 0x20 };
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2022-11-02 00:32:26 +00:00
|
|
|
ASSERT_NE(ChangedValue, settings.peer_socket_tos);
|
|
|
|
|
|
|
|
settings.peer_socket_tos = tr_tos_t(0x20);
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2022-11-02 00:32:26 +00:00
|
|
|
auto val = std::string_view{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindStrView(&var, Key, &val));
|
2022-11-02 00:32:26 +00:00
|
|
|
EXPECT_EQ(ChangedValue.toString(), val);
|
|
|
|
}
|
2023-01-18 08:09:29 +00:00
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadVerify)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_torrent_added_verify_mode;
|
|
|
|
static auto constexpr ChangedValue = TR_VERIFY_ADDED_FULL;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2023-01-18 08:09:29 +00:00
|
|
|
auto const default_value = settings->torrent_added_verify_mode;
|
|
|
|
ASSERT_NE(ChangedValue, default_value);
|
|
|
|
|
2023-08-21 04:15:23 +00:00
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "full");
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2023-01-18 08:09:29 +00:00
|
|
|
EXPECT_EQ(ChangedValue, settings->torrent_added_verify_mode);
|
2023-08-21 04:15:23 +00:00
|
|
|
var.clear();
|
2023-01-18 08:09:29 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-08-21 04:15:23 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ChangedValue);
|
2023-09-08 00:05:16 +00:00
|
|
|
settings->load(var);
|
2023-01-18 08:09:29 +00:00
|
|
|
EXPECT_EQ(ChangedValue, settings->torrent_added_verify_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveVerify)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_torrent_added_verify_mode;
|
|
|
|
static auto constexpr ChangedValue = TR_VERIFY_ADDED_FULL;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2023-01-18 08:09:29 +00:00
|
|
|
ASSERT_NE(ChangedValue, settings.torrent_added_verify_mode);
|
|
|
|
|
|
|
|
settings.torrent_added_verify_mode = ChangedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
auto var = settings.save();
|
2023-01-18 08:09:29 +00:00
|
|
|
auto val = std::string_view{};
|
2023-08-21 04:15:23 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindStrView(&var, Key, &val));
|
2023-01-18 08:09:29 +00:00
|
|
|
EXPECT_EQ("full", val);
|
|
|
|
}
|
2023-09-16 01:23:34 +00:00
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadPreferredTransport)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_preferred_transport;
|
|
|
|
auto constexpr ExpectedValue = TR_PREFER_TCP;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2023-09-16 01:23:34 +00:00
|
|
|
auto const default_value = settings->preferred_transport;
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ExpectedValue);
|
|
|
|
settings->load(var);
|
|
|
|
EXPECT_EQ(ExpectedValue, settings->preferred_transport);
|
|
|
|
var.clear();
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2023-09-16 01:23:34 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddStrView(&var, Key, "tcp");
|
|
|
|
settings->load(var);
|
|
|
|
EXPECT_EQ(ExpectedValue, settings->preferred_transport);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSavePreferredTransport)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_preferred_transport;
|
|
|
|
static auto constexpr ExpectedValue = TR_PREFER_TCP;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2023-09-16 01:23:34 +00:00
|
|
|
auto const default_value = settings.preferred_transport;
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 100);
|
|
|
|
settings.preferred_transport = ExpectedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
var = settings.save();
|
2023-09-16 01:23:34 +00:00
|
|
|
auto val = std::string_view{};
|
|
|
|
EXPECT_TRUE(tr_variantDictFindStrView(&var, Key, &val));
|
|
|
|
EXPECT_EQ("tcp", val);
|
|
|
|
}
|
2024-02-12 15:30:40 +00:00
|
|
|
|
|
|
|
TEST_F(SettingsTest, canLoadSleepPerSecondsDuringVerify)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_sleep_per_seconds_during_verify;
|
|
|
|
auto constexpr ExpectedValue = 90ms;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = std::make_unique<tr_session::Settings>();
|
2024-02-12 15:30:40 +00:00
|
|
|
auto const default_value = settings->sleep_per_seconds_during_verify;
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, ExpectedValue.count());
|
|
|
|
settings->load(var);
|
|
|
|
EXPECT_EQ(ExpectedValue, settings->sleep_per_seconds_during_verify);
|
|
|
|
var.clear();
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
settings = std::make_unique<tr_session::Settings>();
|
2024-02-12 15:30:40 +00:00
|
|
|
tr_variantInitDict(&var, 1);
|
|
|
|
tr_variantDictAddInt(&var, Key, 90);
|
|
|
|
settings->load(var);
|
|
|
|
EXPECT_EQ(ExpectedValue, settings->sleep_per_seconds_during_verify);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SettingsTest, canSaveSleepPerSecondsDuringVerify)
|
|
|
|
{
|
|
|
|
static auto constexpr Key = TR_KEY_sleep_per_seconds_during_verify;
|
|
|
|
static auto constexpr ExpectedValue = 90ms;
|
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto settings = tr_session::Settings{};
|
2024-02-12 15:30:40 +00:00
|
|
|
auto const default_value = settings.sleep_per_seconds_during_verify;
|
|
|
|
ASSERT_NE(ExpectedValue, default_value);
|
|
|
|
|
|
|
|
auto var = tr_variant{};
|
|
|
|
tr_variantInitDict(&var, 100);
|
|
|
|
settings.sleep_per_seconds_during_verify = ExpectedValue;
|
2024-02-15 17:31:09 +00:00
|
|
|
var = settings.save();
|
2024-02-12 15:30:40 +00:00
|
|
|
|
2024-02-15 17:31:09 +00:00
|
|
|
auto val_raw = int64_t{};
|
2024-02-12 15:30:40 +00:00
|
|
|
EXPECT_TRUE(tr_variantDictFindInt(&var, Key, &val_raw));
|
|
|
|
EXPECT_EQ(ExpectedValue, std::chrono::milliseconds{ val_raw });
|
2024-02-15 17:31:09 +00:00
|
|
|
}
|