irccd  3.0.3
cli_fixture.hpp
1 /*
2  * cli_fixture.hpp -- test fixture for irccdctl frontend
3  *
4  * Copyright (c) 2013-2019 David Demelier <markand@malikania.fr>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef IRCCD_TEST_CLI_FIXTURE_HPP
20 #define IRCCD_TEST_CLI_FIXTURE_HPP
21 
27 #include <thread>
28 #include <tuple>
29 #include <vector>
30 
31 #include <boost/asio.hpp>
32 
33 #include <irccd/daemon/bot.hpp>
34 #include <irccd/daemon/plugin_service.hpp>
35 #include <irccd/daemon/rule_service.hpp>
36 #include <irccd/daemon/server_service.hpp>
37 
38 #include <irccd/test/mock_server.hpp>
39 
40 namespace irccd::test {
41 
52 class cli_fixture {
53 private:
54  std::string irccdctl_;
55  std::thread thread_;
56  std::uint16_t port_{0U};
57 
58  boost::asio::io_context service_;
59 
60 protected:
66  daemon::bot bot_{service_};
67 
71  std::shared_ptr<mock_server> server_;
72 
73 public:
77  using outputs = std::vector<std::string>;
78 
82  using result = std::tuple<int, outputs, outputs>;
83 
89  cli_fixture(std::string irccdctl);
90 
95 
102  void start();
103 
110  auto exec(const std::vector<std::string>& args) -> result;
111 };
112 
113 } // !irccd::test
114 
115 #endif // !IRCCD_TEST_CLI_FIXTURE_HPP
irccd::test::cli_fixture::start
void start()
irccd::test::cli_fixture::server_
std::shared_ptr< mock_server > server_
Definition: cli_fixture.hpp:71
irccd::test::cli_fixture::~cli_fixture
~cli_fixture()
irccd::test::cli_fixture::cli_fixture
cli_fixture(std::string irccdctl)
irccd::test::cli_fixture::result
std::tuple< int, outputs, outputs > result
Definition: cli_fixture.hpp:82
irccd::daemon::bot
Irccd main instance.
Definition: bot.hpp:58
irccd::test::cli_fixture
Test fixture for irccdctl frontend.
Definition: cli_fixture.hpp:52
irccd::test::cli_fixture::outputs
std::vector< std::string > outputs
Definition: cli_fixture.hpp:77
irccd::test::cli_fixture::exec
auto exec(const std::vector< std::string > &args) -> result
irccd::test
Namespace for unit tests.
Definition: broken_plugin.hpp:29
irccd::test::cli_fixture::bot_
daemon::bot bot_
Definition: cli_fixture.hpp:66