comparison tests/src/libirccd-daemon/command-server-info/main.cpp @ 809:8460b4a34191

misc: reorganize namespaces, closes #952 @4h
author David Demelier <markand@malikania.fr>
date Fri, 16 Nov 2018 12:25:00 +0100
parents tests/src/libirccd/command-server-info/main.cpp@7145a3df4cb7
children 06cc2f95f479
comparison
equal deleted inserted replaced
808:80bccab4a093 809:8460b4a34191
1 /*
2 * main.cpp -- test server-info remote command
3 *
4 * Copyright (c) 2013-2018 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 #define BOOST_TEST_MODULE "server-info"
20 #include <boost/test/unit_test.hpp>
21
22 #include <irccd/test/command_fixture.hpp>
23
24 using irccd::test::command_fixture;
25 using irccd::test::mock_server;
26
27 using irccd::daemon::server;
28 using irccd::daemon::server_error;
29
30 namespace irccd {
31
32 namespace {
33
34 BOOST_FIXTURE_TEST_SUITE(server_info_fixture_suite, command_fixture)
35
36 BOOST_AUTO_TEST_CASE(basic)
37 {
38 auto server = std::make_unique<mock_server>(ctx_, "test", "example.org");
39
40 server->set_port(8765);
41 server->set_password("none");
42 server->set_nickname("pascal");
43 server->set_username("psc");
44 server->set_realname("Pascal le grand frere");
45 server->set_ctcp_version("yeah");
46 server->set_command_char("@");
47 server->set_ping_timeout(20000);
48
49 bot_.servers().clear();
50 bot_.servers().add(std::move(server));
51
52 const auto [json, code] = request({
53 { "command", "server-info" },
54 { "server", "test" },
55 });
56
57 BOOST_TEST(!code);
58 BOOST_TEST(json.is_object());
59 BOOST_TEST(json["hostname"].get<std::string>() == "example.org");
60 BOOST_TEST(json["name"].get<std::string>() == "test");
61 BOOST_TEST(json["nickname"].get<std::string>() == "pascal");
62 BOOST_TEST(json["port"].get<int>() == 8765);
63 BOOST_TEST(json["realname"].get<std::string>() == "Pascal le grand frere");
64 BOOST_TEST(json["username"].get<std::string>() == "psc");
65 }
66
67 BOOST_AUTO_TEST_SUITE(errors)
68
69 BOOST_AUTO_TEST_CASE(invalid_identifier_1)
70 {
71 const auto [json, code] = request({
72 { "command", "server-info" },
73 { "server", 123456 }
74 });
75
76 BOOST_TEST(code == server_error::invalid_identifier);
77 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier);
78 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
79 }
80
81 BOOST_AUTO_TEST_CASE(invalid_identifier_2)
82 {
83 const auto [json, code] = request({
84 { "command", "server-info" },
85 { "server", "" }
86 });
87
88 BOOST_TEST(code == server_error::invalid_identifier);
89 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier);
90 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
91 }
92
93 BOOST_AUTO_TEST_CASE(not_found)
94 {
95 const auto [json, code] = request({
96 { "command", "server-info" },
97 { "server", "unknown" }
98 });
99
100 BOOST_TEST(code == server_error::not_found);
101 BOOST_TEST(json["error"].get<int>() == server_error::not_found);
102 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
103 }
104
105 BOOST_AUTO_TEST_SUITE_END()
106
107 BOOST_AUTO_TEST_SUITE_END()
108
109 } // !namespace
110
111 } // !irccd