Mercurial > irccd
diff tests/js-plugin/main.cpp @ 522:683eb8ad79d1
Irccd: do not set config in js_plugin load, closes #678
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 13 Nov 2017 19:34:52 +0100 |
parents | |
children | ba81aeb514b8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/js-plugin/main.cpp Mon Nov 13 19:34:52 2017 +0100 @@ -0,0 +1,86 @@ +/* + * main.cpp -- test js_plugin object + * + * Copyright (c) 2013-2017 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define BOOST_TEST_MODULE "Javascript plugin object" +#include <boost/test/unit_test.hpp> + +#include <irccd/irccd.hpp> +#include <irccd/js_plugin.hpp> +#include <irccd/js_irccd_module.hpp> +#include <irccd/js_plugin_module.hpp> + +namespace irccd { + +class test { +protected: + irccd irccd_; + std::shared_ptr<js_plugin> plugin_; + + void load(std::string name, std::string path) + { + plugin_ = std::make_unique<js_plugin>(std::move(name), std::move(path)); + + js_irccd_module().load(irccd_, plugin_); + js_plugin_module().load(irccd_, plugin_); + } +}; + +BOOST_FIXTURE_TEST_SUITE(test_suite, test) + +BOOST_AUTO_TEST_CASE(assign) +{ + load("assign", CMAKE_CURRENT_SOURCE_DIR "/config-assign.js"); + + plugin_->set_config({ + { "key2", "value2" } + }); + plugin_->on_load(irccd_); + + BOOST_TEST(plugin_->config().at("key1") == "value1"); + BOOST_TEST(plugin_->config().at("key2") == "value2"); +} + +BOOST_AUTO_TEST_CASE(fill) +{ + load("assign", CMAKE_CURRENT_SOURCE_DIR "/config-fill.js"); + + plugin_->set_config({ + { "key2", "value2" } + }); + plugin_->on_load(irccd_); + + BOOST_TEST(plugin_->config().at("key1") == "value1"); + BOOST_TEST(plugin_->config().at("key2") == "value2"); +} + +BOOST_AUTO_TEST_CASE(merge_after) +{ + load("assign", CMAKE_CURRENT_SOURCE_DIR "/config-fill.js"); + + plugin_->on_load(irccd_); + plugin_->set_config({ + { "key2", "value2" } + }); + + BOOST_TEST(plugin_->config().at("key1") == "value1"); + BOOST_TEST(plugin_->config().at("key2") == "value2"); +} + +BOOST_AUTO_TEST_SUITE_END() + +} // !irccd