Mercurial > irccd
comparison tests/src/libirccd/command-server-nick/main.cpp @ 611:9fbd1700435b
Tests: reoganize hierarchy
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 15 Dec 2017 15:37:58 +0100 |
parents | tests/src/server-nick-command/main.cpp@22b3cd6f991f |
children | f69b1faf812f |
comparison
equal
deleted
inserted
replaced
610:22b3cd6f991f | 611:9fbd1700435b |
---|---|
1 /* | |
2 * main.cpp -- test server-nick remote command | |
3 * | |
4 * Copyright (c) 2013-2017 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-nick" | |
20 #include <boost/test/unit_test.hpp> | |
21 | |
22 #include <irccd/daemon/server_service.hpp> | |
23 | |
24 #include <irccd/test/command_test.hpp> | |
25 #include <irccd/test/journal_server.hpp> | |
26 | |
27 namespace irccd { | |
28 | |
29 namespace { | |
30 | |
31 class server_nick_test : public command_test<server_nick_command> { | |
32 protected: | |
33 std::shared_ptr<journal_server> server_{new journal_server(service_, "test")}; | |
34 | |
35 server_nick_test() | |
36 { | |
37 daemon_->servers().add(server_); | |
38 } | |
39 }; | |
40 | |
41 } // !namespace | |
42 | |
43 BOOST_FIXTURE_TEST_SUITE(server_nick_test_suite, server_nick_test) | |
44 | |
45 BOOST_AUTO_TEST_CASE(basic) | |
46 { | |
47 nlohmann::json result; | |
48 | |
49 ctl_->send({ | |
50 { "command", "server-nick" }, | |
51 { "server", "test" }, | |
52 { "nickname", "chris" } | |
53 }); | |
54 ctl_->recv([&] (auto, auto msg) { | |
55 result = msg; | |
56 }); | |
57 | |
58 wait_for([&] () { | |
59 return result.is_object(); | |
60 }); | |
61 | |
62 BOOST_TEST(result.is_object()); | |
63 BOOST_TEST(server_->nickname() == "chris"); | |
64 } | |
65 | |
66 BOOST_AUTO_TEST_SUITE(errors) | |
67 | |
68 BOOST_AUTO_TEST_CASE(invalid_identifier_1) | |
69 { | |
70 boost::system::error_code result; | |
71 nlohmann::json message; | |
72 | |
73 ctl_->send({ | |
74 { "command", "server-nick" }, | |
75 { "server", 123456 }, | |
76 { "nickname", "chris" } | |
77 }); | |
78 ctl_->recv([&] (auto rresult, auto rmessage) { | |
79 result = rresult; | |
80 message = rmessage; | |
81 }); | |
82 | |
83 wait_for([&] { | |
84 return result; | |
85 }); | |
86 | |
87 BOOST_TEST(result == server_error::invalid_identifier); | |
88 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_identifier); | |
89 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
90 } | |
91 | |
92 BOOST_AUTO_TEST_CASE(invalid_identifier_2) | |
93 { | |
94 boost::system::error_code result; | |
95 nlohmann::json message; | |
96 | |
97 ctl_->send({ | |
98 { "command", "server-nick" }, | |
99 { "server", "" }, | |
100 { "nickname", "chris" } | |
101 }); | |
102 ctl_->recv([&] (auto rresult, auto rmessage) { | |
103 result = rresult; | |
104 message = rmessage; | |
105 }); | |
106 | |
107 wait_for([&] { | |
108 return result; | |
109 }); | |
110 | |
111 BOOST_TEST(result == server_error::invalid_identifier); | |
112 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_identifier); | |
113 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
114 } | |
115 | |
116 BOOST_AUTO_TEST_CASE(invalid_nickname_1) | |
117 { | |
118 boost::system::error_code result; | |
119 nlohmann::json message; | |
120 | |
121 ctl_->send({ | |
122 { "command", "server-nick" }, | |
123 { "server", "test" }, | |
124 { "nickname", "" } | |
125 }); | |
126 ctl_->recv([&] (auto rresult, auto rmessage) { | |
127 result = rresult; | |
128 message = rmessage; | |
129 }); | |
130 | |
131 wait_for([&] { | |
132 return result; | |
133 }); | |
134 | |
135 BOOST_TEST(result == server_error::invalid_nickname); | |
136 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_nickname); | |
137 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
138 } | |
139 | |
140 BOOST_AUTO_TEST_CASE(invalid_nickname_2) | |
141 { | |
142 boost::system::error_code result; | |
143 nlohmann::json message; | |
144 | |
145 ctl_->send({ | |
146 { "command", "server-nick" }, | |
147 { "server", "test" }, | |
148 { "nickname", 123456 } | |
149 }); | |
150 ctl_->recv([&] (auto rresult, auto rmessage) { | |
151 result = rresult; | |
152 message = rmessage; | |
153 }); | |
154 | |
155 wait_for([&] { | |
156 return result; | |
157 }); | |
158 | |
159 BOOST_TEST(result == server_error::invalid_nickname); | |
160 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_nickname); | |
161 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
162 } | |
163 BOOST_AUTO_TEST_CASE(not_found) | |
164 { | |
165 boost::system::error_code result; | |
166 nlohmann::json message; | |
167 | |
168 ctl_->send({ | |
169 { "command", "server-nick" }, | |
170 { "server", "unknown" }, | |
171 { "nickname", "chris" } | |
172 }); | |
173 ctl_->recv([&] (auto rresult, auto rmessage) { | |
174 result = rresult; | |
175 message = rmessage; | |
176 }); | |
177 | |
178 wait_for([&] { | |
179 return result; | |
180 }); | |
181 | |
182 BOOST_TEST(result == server_error::not_found); | |
183 BOOST_TEST(message["error"].template get<int>() == server_error::not_found); | |
184 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
185 } | |
186 | |
187 BOOST_AUTO_TEST_SUITE_END() | |
188 | |
189 BOOST_AUTO_TEST_SUITE_END() | |
190 | |
191 } // !irccd |