Mercurial > irccd
comparison tests/src/libirccd/command-server-topic/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-topic-command/main.cpp@22b3cd6f991f |
children | f69b1faf812f |
comparison
equal
deleted
inserted
replaced
610:22b3cd6f991f | 611:9fbd1700435b |
---|---|
1 /* | |
2 * main.cpp -- test server-topic 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-topic" | |
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_topic_test : public command_test<server_topic_command> { | |
32 protected: | |
33 std::shared_ptr<journal_server> server_{new journal_server(service_, "test")}; | |
34 | |
35 server_topic_test() | |
36 { | |
37 daemon_->servers().add(server_); | |
38 } | |
39 }; | |
40 | |
41 } // !namespace | |
42 | |
43 BOOST_FIXTURE_TEST_SUITE(server_topic_test_suite, server_topic_test) | |
44 | |
45 BOOST_AUTO_TEST_CASE(basic) | |
46 { | |
47 ctl_->send({ | |
48 { "command", "server-topic" }, | |
49 { "server", "test" }, | |
50 { "channel", "#staff" }, | |
51 { "topic", "new version" } | |
52 }); | |
53 | |
54 wait_for([this] () { | |
55 return !server_->cqueue().empty(); | |
56 }); | |
57 | |
58 auto cmd = server_->cqueue().back(); | |
59 | |
60 BOOST_TEST(cmd["command"].get<std::string>() == "topic"); | |
61 BOOST_TEST(cmd["channel"].get<std::string>() == "#staff"); | |
62 BOOST_TEST(cmd["topic"].get<std::string>() == "new version"); | |
63 } | |
64 | |
65 BOOST_AUTO_TEST_SUITE(errors) | |
66 | |
67 BOOST_AUTO_TEST_CASE(invalid_identifier_1) | |
68 { | |
69 boost::system::error_code result; | |
70 nlohmann::json message; | |
71 | |
72 ctl_->send({ | |
73 { "command", "server-topic" }, | |
74 { "server", 123456 }, | |
75 { "channel", "#music" }, | |
76 { "topic", "plop" } | |
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-topic" }, | |
99 { "server", "" }, | |
100 { "channel", "#music" }, | |
101 { "topic", "plop" } | |
102 }); | |
103 ctl_->recv([&] (auto rresult, auto rmessage) { | |
104 result = rresult; | |
105 message = rmessage; | |
106 }); | |
107 | |
108 wait_for([&] { | |
109 return result; | |
110 }); | |
111 | |
112 BOOST_TEST(result == server_error::invalid_identifier); | |
113 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_identifier); | |
114 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
115 } | |
116 | |
117 BOOST_AUTO_TEST_CASE(invalid_channel_1) | |
118 { | |
119 boost::system::error_code result; | |
120 nlohmann::json message; | |
121 | |
122 ctl_->send({ | |
123 { "command", "server-topic" }, | |
124 { "server", "test" }, | |
125 { "channel", "" }, | |
126 { "topic", "plop" } | |
127 }); | |
128 ctl_->recv([&] (auto rresult, auto rmessage) { | |
129 result = rresult; | |
130 message = rmessage; | |
131 }); | |
132 | |
133 wait_for([&] { | |
134 return result; | |
135 }); | |
136 | |
137 BOOST_TEST(result == server_error::invalid_channel); | |
138 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_channel); | |
139 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
140 } | |
141 | |
142 BOOST_AUTO_TEST_CASE(invalid_channel_2) | |
143 { | |
144 boost::system::error_code result; | |
145 nlohmann::json message; | |
146 | |
147 ctl_->send({ | |
148 { "command", "server-topic" }, | |
149 { "server", "test" }, | |
150 { "channel", 123456 }, | |
151 { "topic", "plop" } | |
152 }); | |
153 ctl_->recv([&] (auto rresult, auto rmessage) { | |
154 result = rresult; | |
155 message = rmessage; | |
156 }); | |
157 | |
158 wait_for([&] { | |
159 return result; | |
160 }); | |
161 | |
162 BOOST_TEST(result == server_error::invalid_channel); | |
163 BOOST_TEST(message["error"].template get<int>() == server_error::invalid_channel); | |
164 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
165 } | |
166 | |
167 BOOST_AUTO_TEST_CASE(not_found) | |
168 { | |
169 boost::system::error_code result; | |
170 nlohmann::json message; | |
171 | |
172 ctl_->send({ | |
173 { "command", "server-topic" }, | |
174 { "server", "unknown" }, | |
175 { "channel", "#music" }, | |
176 { "topic", "plop" } | |
177 }); | |
178 ctl_->recv([&] (auto rresult, auto rmessage) { | |
179 result = rresult; | |
180 message = rmessage; | |
181 }); | |
182 | |
183 wait_for([&] { | |
184 return result; | |
185 }); | |
186 | |
187 BOOST_TEST(result == server_error::not_found); | |
188 BOOST_TEST(message["error"].template get<int>() == server_error::not_found); | |
189 BOOST_TEST(message["errorCategory"].template get<std::string>() == "server"); | |
190 } | |
191 | |
192 BOOST_AUTO_TEST_SUITE_END() | |
193 | |
194 BOOST_AUTO_TEST_SUITE_END() | |
195 | |
196 } // !irccd |