From 1fa20fcbae6512a4fff237441f0fd2b9784a041e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Wed, 8 Jan 2025 15:59:03 +0100 Subject: [PATCH] Try to fix tests --- .../server/startupOptions/TestLoader.cpp | 65 +++++++++++++++---- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/tests/unit/sources/server/startupOptions/TestLoader.cpp b/tests/unit/sources/server/startupOptions/TestLoader.cpp index da16c6719..7eeaf3051 100644 --- a/tests/unit/sources/server/startupOptions/TestLoader.cpp +++ b/tests/unit/sources/server/startupOptions/TestLoader.cpp @@ -30,7 +30,7 @@ class CTestPath final testCommon::filesystem::createDirectory(m_testDirectory); } - virtual ~CTestPath() + ~CTestPath() { // Clean-up TestDirectory try @@ -60,7 +60,7 @@ class CTestConfigFile final testCommon::filesystem::removeFile(m_configFile, false); } - virtual ~CTestConfigFile() + ~CTestConfigFile() { // Clean-up testCommon::filesystem::removeFile(m_configFile, false); @@ -89,7 +89,6 @@ static const std::string testFalsePath("FalsePath"); #include #include #include -#include #include BOOST_AUTO_TEST_SUITE(TestLoader) @@ -98,15 +97,59 @@ BOOST_AUTO_TEST_SUITE(TestLoader) class CStartupOptionMockup final { public: - class CMyConf final: public Poco::Util::MapConfiguration + class CMyConf final: public Poco::Util::AbstractConfiguration { public: CMyConf() = default; - virtual ~CMyConf() = default; + ~CMyConf() override = default; + + protected: + bool getRaw(const std::string& key, std::string& value) const override + { + if (m_values.find(key) == m_values.end()) + return false; + + value = m_values.at(key); + return true; + } + + void setRaw(const std::string& key, const std::string& value) override + { + m_values[key] = value; + } + + void enumerate(const std::string& key, Keys& range) const override + { + std::set keys; + auto prefix = key; + if (!prefix.empty()) + prefix += '.'; + const auto psize = prefix.size(); + for (const auto& p : m_values) + { + if (p.first.compare(0, psize, prefix) == 0) + { + std::string subKey; + const auto end = p.first.find('.', psize); + if (end == std::string::npos) + subKey = p.first.substr(psize); + else + subKey = p.first.substr(psize, end - psize); + if (keys.find(subKey) == keys.end()) + { + range.push_back(subKey); + keys.insert(subKey); + } + } + } + } + + private: + std::map m_values; }; CStartupOptionMockup(int argc, const char* argv[], bool unixStyle) - : m_config(new CMyConf), m_options(*(m_config.get())) + : m_options(m_config) { m_options.defineOptions(m_os); Poco::Util::OptionProcessor processor(m_os); @@ -131,11 +174,6 @@ BOOST_AUTO_TEST_SUITE(TestLoader) return m_options; } - Poco::AutoPtr& config() - { - return m_config; - } - private: void handleOption(Poco::Util::OptionSet& os, const std::string& name, const std::string& value) { @@ -146,7 +184,7 @@ BOOST_AUTO_TEST_SUITE(TestLoader) } if (!option.binding().empty()) { - m_config->setString(std::string(option.binding()), std::string(value)); + m_config.setString(std::string(option.binding()), std::string(value)); } if (option.callback()) { @@ -155,7 +193,8 @@ BOOST_AUTO_TEST_SUITE(TestLoader) } Poco::Util::OptionSet m_os; - Poco::AutoPtr m_config; + CMyConf m_config; + //Poco::AutoPtr m_config; startupOptions::CStartupOptions m_options; };