Mercurial > irccd
changeset 306:c6eed76f8646
Tests: add test for server-invite, #559
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 19 Oct 2016 17:55:49 +0200 |
parents | e1e596a75355 |
children | 2fa974c03282 |
files | libirccd/irccd/cmd-server-invite.cpp libirccd/irccd/cmd-server-invite.hpp tests/CMakeLists.txt tests/cmd-server-invite/CMakeLists.txt tests/cmd-server-invite/main.cpp |
diffstat | 5 files changed, 112 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/libirccd/irccd/cmd-server-invite.cpp Tue Oct 18 18:30:45 2016 +0200 +++ b/libirccd/irccd/cmd-server-invite.cpp Wed Oct 19 17:55:49 2016 +0200 @@ -20,50 +20,25 @@ #include "irccd.hpp" #include "server.hpp" #include "service-server.hpp" +#include "transport.hpp" +#include "util.hpp" namespace irccd { namespace command { ServerInviteCommand::ServerInviteCommand() - : Command("server-invite", "Server", "Invite someone into a channel") + : Command("server-invite") { } -std::vector<Command::Arg> ServerInviteCommand::args() const -{ - return { - { "server", true }, - { "nickname", true }, - { "channel", true } - }; -} - -std::vector<Command::Property> ServerInviteCommand::properties() const +void ServerInviteCommand::exec(Irccd &irccd, TransportClient &client, const nlohmann::json &args) { - return { - { "server", { nlohmann::json::value_t::string }}, - { "target", { nlohmann::json::value_t::string }}, - { "channel", { nlohmann::json::value_t::string }} - }; -} - -nlohmann::json ServerInviteCommand::request(Irccdctl &, const CommandRequest &args) const -{ - return nlohmann::json::object({ - { "server", args.args()[0] }, - { "target", args.args()[1] }, - { "channel", args.args()[2] } - }); -} - -nlohmann::json ServerInviteCommand::exec(Irccd &irccd, const nlohmann::json &request) const -{ - Command::exec(irccd, request); - - irccd.servers().require(request["server"])->invite(request["target"], request["channel"]); - - return nlohmann::json::object(); + irccd.servers().require(util::json::requireIdentifier(args, "server"))->invite( + util::json::requireString(args, "target"), + util::json::requireString(args, "channel") + ); + client.success("server-invite"); } } // !command
--- a/libirccd/irccd/cmd-server-invite.hpp Tue Oct 18 18:30:45 2016 +0200 +++ b/libirccd/irccd/cmd-server-invite.hpp Wed Oct 19 17:55:49 2016 +0200 @@ -41,24 +41,9 @@ IRCCD_EXPORT ServerInviteCommand(); /** - * \copydoc Command::args - */ - IRCCD_EXPORT std::vector<Arg> args() const override; - - /** - * \copydoc Command::properties - */ - IRCCD_EXPORT std::vector<Property> properties() const override; - - /** - * \copydoc Command::request - */ - IRCCD_EXPORT nlohmann::json request(Irccdctl &irccdctl, const CommandRequest &args) const override; - - /** * \copydoc Command::exec */ - IRCCD_EXPORT nlohmann::json exec(Irccd &irccd, const nlohmann::json &request) const override; + IRCCD_EXPORT void exec(Irccd &irccd, TransportClient &client, const nlohmann::json &args) override; }; } // !command
--- a/tests/CMakeLists.txt Tue Oct 18 18:30:45 2016 +0200 +++ b/tests/CMakeLists.txt Wed Oct 19 17:55:49 2016 +0200 @@ -24,6 +24,8 @@ add_subdirectory(cmd-server-cnotice) add_subdirectory(cmd-server-disconnect) add_subdirectory(cmd-server-info) + add_subdirectory(cmd-server-invite) + add_subdirectory(cmd-server-list) add_subdirectory(cmd-server-me) add_subdirectory(cmd-server-message) add_subdirectory(cmd-server-mode)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/cmd-server-invite/CMakeLists.txt Wed Oct 19 17:55:49 2016 +0200 @@ -0,0 +1,24 @@ +# +# CMakeLists.txt -- CMake build system for irccd +# +# Copyright (c) 2013-2016 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. +# + +irccd_define_test( + NAME cmd-server-invite + SOURCES main.cpp + LIBRARIES libirccd libirccdctl +) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/cmd-server-invite/main.cpp Wed Oct 19 17:55:49 2016 +0200 @@ -0,0 +1,76 @@ +/* + * main.cpp -- test server-invite remote command + * + * Copyright (c) 2013-2016 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. + */ + +#include <cmd-server-invite.hpp> +#include <command-tester.hpp> +#include <server-tester.hpp> + +using namespace irccd; +using namespace irccd::command; + +namespace { + +std::string target; +std::string channel; + +} // !namespace + +class ServerInviteTest : public ServerTester { +public: + void invite(std::string target, std::string channel) override + { + ::target = target; + ::channel = channel; + } +}; + +class ServerInviteCommandTest : public CommandTester { +public: + ServerInviteCommandTest() + : CommandTester(std::make_unique<ServerInviteCommand>(), + std::make_unique<ServerInviteTest>()) + { + m_irccdctl.client().request({ + { "command", "server-invite" }, + { "server", "test" }, + { "target", "francis" }, + { "channel", "#music" } + }); + } +}; + +TEST_F(ServerInviteCommandTest, basic) +{ + try { + poll([&] () { + return !target.empty() && !channel.empty(); + }); + + ASSERT_EQ("francis", target); + ASSERT_EQ("#music", channel); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}