diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index 2790c08e..60df830c 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -26,13 +26,13 @@ namespace repertory { constexpr const auto default_api_auth_size{48U}; constexpr const auto default_download_timeout_secs{30U}; constexpr const auto default_eviction_delay_mins{1U}; -constexpr const auto default_high_freq_interval_secs{30U}; +constexpr const auto default_high_freq_interval_secs{std::uint16_t{30U}}; constexpr const auto default_low_freq_interval_secs{std::uint16_t(60U * 60U)}; constexpr const auto default_max_cache_size_bytes{ std::uint64_t(20ULL * 1024ULL * 1024ULL * 1024ULL), }; constexpr const auto default_max_upload_count{5U}; -constexpr const auto default_med_freq_interval_secs{2U * 60U}; +constexpr const auto default_med_freq_interval_secs{std::uint16_t{2U * 60U}}; constexpr const auto default_online_check_retry_secs{60U}; constexpr const auto default_orphaned_file_retention_days{15U}; constexpr const auto default_retry_read_count{6U}; diff --git a/repertory/librepertory/src/app_config.cpp b/repertory/librepertory/src/app_config.cpp index cbc7cd5f..5aef7c7e 100644 --- a/repertory/librepertory/src/app_config.cpp +++ b/repertory/librepertory/src/app_config.cpp @@ -349,7 +349,7 @@ app_config::app_config(const provider_type &prov, { JSON_HIGH_FREQ_INTERVAL_SECS, [this](const std::string &value) { - set_high_frequency_interval_secs(utils::string::to_uint8(value)); + set_high_frequency_interval_secs(utils::string::to_uint16(value)); return std::to_string(get_high_frequency_interval_secs()); }, }, @@ -401,14 +401,14 @@ app_config::app_config(const provider_type &prov, { JSON_LOW_FREQ_INTERVAL_SECS, [this](const std::string &value) { - set_low_frequency_interval_secs(utils::string::to_uint8(value)); + set_low_frequency_interval_secs(utils::string::to_uint16(value)); return std::to_string(get_low_frequency_interval_secs()); }, }, { JSON_MED_FREQ_INTERVAL_SECS, [this](const std::string &value) { - set_med_frequency_interval_secs(utils::string::to_uint8(value)); + set_med_frequency_interval_secs(utils::string::to_uint16(value)); return std::to_string(get_med_frequency_interval_secs()); }, }, diff --git a/repertory/repertory_test/src/app_config_test.cpp b/repertory/repertory_test/src/app_config_test.cpp index 62a0338a..06b2fc1a 100644 --- a/repertory/repertory_test/src/app_config_test.cpp +++ b/repertory/repertory_test/src/app_config_test.cpp @@ -181,91 +181,132 @@ static void defaults_tests(const json &json_data, provider_type prov) { } } +template +static void test_getter_setter(app_config &cfg, get_t getter, set_t setter, + val_t val1, val_t val2, const std::string &key, + const std::string &val_str) { + (cfg.*setter)(val1); + ASSERT_TRUE((cfg.*getter)() == val1); + + (cfg.*setter)(val2); + ASSERT_TRUE((cfg.*getter)() == val2); + + EXPECT_STREQ(val_str.c_str(), cfg.set_value_by_name(key, val_str).c_str()); +} + static void common_tests(app_config &config, provider_type prov) { ASSERT_EQ(config.get_provider_type(), prov); std::map> methods{ {JSON_API_AUTH, [](app_config &cfg) { - cfg.set_api_auth(""); - EXPECT_STREQ("", cfg.get_api_auth().c_str()); - - cfg.set_api_auth("test"); - EXPECT_STREQ("test", cfg.get_api_auth().c_str()); - - auto value = cfg.set_value_by_name(JSON_API_AUTH, "test2"); - EXPECT_STREQ("test2", value.c_str()); - EXPECT_STREQ("test2", cfg.get_api_auth().c_str()); - - value = cfg.get_value_by_name(JSON_API_AUTH); - EXPECT_STREQ("test2", value.c_str()); + test_getter_setter(cfg, &app_config::get_api_auth, + &app_config::set_api_auth, "", "auth", + JSON_API_AUTH, "auth2"); }}, {JSON_API_PORT, [](app_config &cfg) { - cfg.set_api_port(0U); - EXPECT_EQ(std::uint16_t(0U), cfg.get_api_port()); - - cfg.set_api_port(1024U); - EXPECT_EQ(std::uint16_t(1024U), cfg.get_api_port()); - - auto value = cfg.set_value_by_name(JSON_API_PORT, "1025"); - EXPECT_STREQ("1025", value.c_str()); - EXPECT_EQ(std::uint16_t(1025U), cfg.get_api_port()); - - value = cfg.get_value_by_name(JSON_API_PORT); - EXPECT_STREQ("1025", value.c_str()); + test_getter_setter(cfg, &app_config::get_api_port, + &app_config::set_api_port, std::uint16_t{0U}, + std::uint16_t{1024U}, JSON_API_PORT, "1025"); }}, {JSON_API_USER, [](app_config &cfg) { - cfg.set_api_user(""); - EXPECT_STREQ("", cfg.get_api_user().c_str()); - - cfg.set_api_user("test"); - EXPECT_STREQ("test", cfg.get_api_user().c_str()); - - auto value = cfg.set_value_by_name(JSON_API_USER, "test2"); - EXPECT_STREQ("test2", value.c_str()); - EXPECT_STREQ("test2", cfg.get_api_user().c_str()); - - value = cfg.get_value_by_name(JSON_API_USER); - EXPECT_STREQ("test2", value.c_str()); + test_getter_setter(cfg, &app_config::get_api_user, + &app_config::set_api_user, "", "user", + JSON_API_USER, "user2"); }}, {JSON_DOWNLOAD_TIMEOUT_SECS, [](app_config &cfg) { - cfg.set_download_timeout_secs(min_download_timeout_secs); - EXPECT_EQ(std::uint8_t(min_download_timeout_secs), - cfg.get_download_timeout_secs()); - - cfg.set_download_timeout_secs(min_download_timeout_secs + 1U); - EXPECT_EQ(std::uint8_t(min_download_timeout_secs + 1U), - cfg.get_download_timeout_secs()); - - auto value = cfg.set_value_by_name(JSON_DOWNLOAD_TIMEOUT_SECS, "26"); - EXPECT_STREQ("26", value.c_str()); - EXPECT_EQ(std::uint8_t(26U), cfg.get_download_timeout_secs()); - - value = cfg.get_value_by_name(JSON_DOWNLOAD_TIMEOUT_SECS); - EXPECT_STREQ("26", value.c_str()); + test_getter_setter(cfg, &app_config::get_download_timeout_secs, + &app_config::set_download_timeout_secs, + min_download_timeout_secs, + std::uint8_t{min_download_timeout_secs + 1U}, + JSON_DOWNLOAD_TIMEOUT_SECS, "26"); cfg.set_download_timeout_secs(min_download_timeout_secs - 1U); EXPECT_EQ(min_download_timeout_secs, cfg.get_download_timeout_secs()); }}, - {JSON_DATABASE_TYPE, [](auto &&cfg) {}}, - {JSON_ENABLE_DOWNLOAD_TIMEOUT, [](auto &&cfg) {}}, - {JSON_ENABLE_DRIVE_EVENTS, [](auto &&cfg) {}}, + {JSON_DATABASE_TYPE, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_database_type, + &app_config::set_database_type, + database_type::rocksdb, database_type::sqlite, + JSON_DATABASE_TYPE, "rocksdb"); + }}, + {JSON_ENABLE_DOWNLOAD_TIMEOUT, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_enable_download_timeout, + &app_config::set_enable_download_timeout, true, + false, JSON_ENABLE_DOWNLOAD_TIMEOUT, "1"); + }}, + {JSON_ENABLE_DRIVE_EVENTS, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_enable_drive_events, + &app_config::set_enable_drive_events, true, false, + JSON_ENABLE_DRIVE_EVENTS, "1"); + }}, #if defined(_WIN32) - {JSON_ENABLE_MOUNT_MANAGER, [](auto &&cfg) {}}, + {JSON_ENABLE_REMOTE_MOUNT, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_enable_remote_mount, + &app_config::set_enable_remote_mount, true, false, + JSON_ENABLE_REMOTE_MOUNT, "1"); + }}, #endif // defined(_WIN32) {JSON_ENCRYPT_CONFIG, [](auto &&cfg) {}}, - {JSON_EVENT_LEVEL, [](auto &&cfg) {}}, - {JSON_EVICTION_DELAY_MINS, [](auto &&cfg) {}}, - {JSON_EVICTION_USE_ACCESS_TIME, [](auto &&cfg) {}}, - {JSON_HIGH_FREQ_INTERVAL_SECS, [](auto &&cfg) {}}, + {JSON_EVENT_LEVEL, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_event_level, + &app_config::set_event_level, event_level::critical, + event_level::debug, JSON_EVENT_LEVEL, "info"); + }}, + {JSON_EVICTION_DELAY_MINS, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_eviction_delay_mins, + &app_config::set_eviction_delay_mins, + std::uint32_t{0U}, std::uint32_t{1U}, + JSON_EVICTION_DELAY_MINS, "2"); + }}, + {JSON_EVICTION_USE_ACCESS_TIME, + [](app_config &cfg) { + test_getter_setter(cfg, &app_config::get_eviction_uses_accessed_time, + &app_config::set_eviction_uses_accessed_time, true, + false, JSON_EVICTION_USE_ACCESS_TIME, "1"); + }}, + {JSON_HIGH_FREQ_INTERVAL_SECS, + [](app_config &cfg) { + test_getter_setter( + cfg, &app_config::get_high_frequency_interval_secs, + &app_config::set_high_frequency_interval_secs, + std::uint16_t{default_high_freq_interval_secs + 1U}, + std::uint16_t{default_high_freq_interval_secs + 2U}, + JSON_HIGH_FREQ_INTERVAL_SECS, + std::to_string(default_high_freq_interval_secs + 3U)); + }}, {JSON_HOST_CONFIG, [](auto &&cfg) {}}, - {JSON_LOW_FREQ_INTERVAL_SECS, [](auto &&cfg) {}}, + {JSON_LOW_FREQ_INTERVAL_SECS, + [](app_config &cfg) { + test_getter_setter( + cfg, &app_config::get_low_frequency_interval_secs, + &app_config::set_low_frequency_interval_secs, + std::uint16_t{default_low_freq_interval_secs + 1U}, + std::uint16_t{default_low_freq_interval_secs + 2U}, + JSON_LOW_FREQ_INTERVAL_SECS, + std::to_string(default_low_freq_interval_secs + 3U)); + }}, {JSON_MAX_CACHE_SIZE_BYTES, [](auto &&cfg) {}}, {JSON_MAX_UPLOAD_COUNT, [](auto &&cfg) {}}, - {JSON_MED_FREQ_INTERVAL_SECS, [](auto &&cfg) {}}, + {JSON_MED_FREQ_INTERVAL_SECS, + [](app_config &cfg) { + test_getter_setter( + cfg, &app_config::get_med_frequency_interval_secs, + &app_config::set_med_frequency_interval_secs, + std::uint16_t{default_med_freq_interval_secs + 1U}, + std::uint16_t{default_med_freq_interval_secs + 2U}, + JSON_MED_FREQ_INTERVAL_SECS, + std::to_string(default_med_freq_interval_secs + 3U)); + }}, {JSON_ONLINE_CHECK_RETRY_SECS, [](auto &&cfg) {}}, {JSON_ORPHANED_FILE_RETENTION_DAYS, [](auto &&cfg) {}}, {JSON_PREFERRED_DOWNLOAD_TYPE, [](auto &&cfg) {}},