Mercurial > irccd
diff tests/cmd-plugin-config/main.cpp @ 555:9b6b0d7d89c6
Tests: convert cmd-plugin-*, #593
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 24 Nov 2017 21:04:32 +0100 |
parents | 7e273b7f4f92 |
children | 153e84e7b09b |
line wrap: on
line diff
--- a/tests/cmd-plugin-config/main.cpp Fri Nov 24 20:30:42 2017 +0100 +++ b/tests/cmd-plugin-config/main.cpp Fri Nov 24 21:04:32 2017 +0100 @@ -16,136 +16,119 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <command.hpp> -#include <command-tester.hpp> -#include <server-tester.hpp> -#include <service.hpp> +#define BOOST_TEST_MODULE "plugin-config" +#include <boost/test/unit_test.hpp> -using namespace irccd; +#include <irccd/command.hpp> +#include <irccd/plugin_service.hpp> + +#include <command_test.hpp> + +namespace irccd { namespace { -struct CustomPlugin : public plugin { - plugin_config m_config; +class custom_plugin : public plugin { +public: + plugin_config config_; - CustomPlugin(std::string name = "test") + custom_plugin(std::string name = "test") : plugin(std::move(name), "") { } plugin_config config() override { - return m_config; + return config_; } void set_config(plugin_config config) override { - m_config = std::move(config); - } -}; - -class PluginConfigCommandTest : public CommandTester { -public: - PluginConfigCommandTest() - : CommandTester(std::make_unique<plugin_config_command>()) - { + config_ = std::move(config); } }; -TEST_F(PluginConfigCommandTest, set) -{ - try { - m_irccd.plugins().add(std::make_unique<CustomPlugin>("test")); - m_irccdctl.client().request({ - { "command", "plugin-config" }, - { "plugin", "test" }, - { "variable", "verbosy" }, - { "value", "falsy" } - }); +} // !namespace + +BOOST_FIXTURE_TEST_SUITE(plugin_config_test_suite, command_test<plugin_config_command>) - poll([&] { - return !m_irccd.plugins().require("test")->config().empty(); - }); - - auto config = m_irccd.plugins().require("test")->config(); +BOOST_AUTO_TEST_CASE(set) +{ + daemon_->plugins().add(std::make_unique<custom_plugin>("test")); + ctl_->send({ + { "command", "plugin-config" }, + { "plugin", "test" }, + { "variable", "verbosy" }, + { "value", "falsy" } + }); - ASSERT_FALSE(config.empty()); - ASSERT_EQ("falsy", config["verbosy"]); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + wait_for([&] { + return !daemon_->plugins().require("test")->config().empty(); + }); + + auto config = daemon_->plugins().require("test")->config(); + + BOOST_TEST(!config.empty()); + BOOST_TEST(config["verbosy"] == "falsy"); } -TEST_F(PluginConfigCommandTest, get) +BOOST_AUTO_TEST_CASE(get) { - try { - auto plugin = std::make_unique<CustomPlugin>("test"); - auto json = nlohmann::json(); + auto plugin = std::make_unique<custom_plugin>("test"); + auto json = nlohmann::json(); - plugin->set_config({ - { "x1", "10" }, - { "x2", "20" } - }); + plugin->set_config({ + { "x1", "10" }, + { "x2", "20" } + }); - m_irccd.plugins().add(std::move(plugin)); - m_irccdctl.client().request({ - { "command", "plugin-config" }, - { "plugin", "test" }, - { "variable", "x1" } - }); - m_irccdctl.client().onMessage.connect([&] (auto message) { - json = std::move(message); - }); + daemon_->plugins().add(std::move(plugin)); + ctl_->send({ + { "command", "plugin-config" }, + { "plugin", "test" }, + { "variable", "x1" } + }); + ctl_->recv([&] (auto, auto message) { + json = std::move(message); + }); - poll([&] { - return json.is_object(); - }); + wait_for([&] { + return json.is_object(); + }); - ASSERT_TRUE(json.is_object()); - ASSERT_EQ("10", json["variables"]["x1"]); - ASSERT_TRUE(json["variables"]["x2"].is_null()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + BOOST_TEST(json.is_object()); + BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); + BOOST_TEST(json["variables"]["x2"].is_null()); } -TEST_F(PluginConfigCommandTest, getAll) +BOOST_AUTO_TEST_CASE(getall) { - try { - auto plugin = std::make_unique<CustomPlugin>("test"); - auto json = nlohmann::json(); + auto plugin = std::make_unique<custom_plugin>("test"); + auto json = nlohmann::json(); - plugin->set_config({ - { "x1", "10" }, - { "x2", "20" } - }); + plugin->set_config({ + { "x1", "10" }, + { "x2", "20" } + }); - m_irccd.plugins().add(std::move(plugin)); - m_irccdctl.client().request({ - { "command", "plugin-config" }, - { "plugin", "test" } - }); - m_irccdctl.client().onMessage.connect([&] (auto message) { - json = std::move(message); - }); + daemon_->plugins().add(std::move(plugin)); + ctl_->send({ + { "command", "plugin-config" }, + { "plugin", "test" } + }); + ctl_->recv([&] (auto, auto message) { + json = std::move(message); + }); - poll([&] { - return json.is_object(); - }); + wait_for([&] { + return json.is_object(); + }); - ASSERT_TRUE(json.is_object()); - ASSERT_EQ("10", json["variables"]["x1"]); - ASSERT_EQ("20", json["variables"]["x2"]); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + BOOST_TEST(json.is_object()); + BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); + BOOST_TEST(json["variables"]["x2"].get<std::string>() == "20"); } -} // !namespace +BOOST_AUTO_TEST_SUITE_END() -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +} // !irccd