comparison tests/src/libirccd/command-server-me/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-me-command/main.cpp@22b3cd6f991f
children f69b1faf812f
comparison
equal deleted inserted replaced
610:22b3cd6f991f 611:9fbd1700435b
1 /*
2 * main.cpp -- test server-me 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-me"
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_me_test : public command_test<server_me_command> {
32 protected:
33 std::shared_ptr<journal_server> server_{new journal_server(service_, "test")};
34
35 server_me_test()
36 {
37 daemon_->servers().add(server_);
38 }
39 };
40
41 } // !namespace
42
43 BOOST_FIXTURE_TEST_SUITE(server_me_test_suite, server_me_test)
44
45 BOOST_AUTO_TEST_CASE(basic)
46 {
47 ctl_->send({
48 { "command", "server-me" },
49 { "server", "test" },
50 { "target", "jean" },
51 { "message", "hello!" }
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>() == "me");
61 BOOST_TEST(cmd["message"].get<std::string>() == "hello!");
62 BOOST_TEST(cmd["target"].get<std::string>() == "jean");
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-me" },
74 { "server", 123456 },
75 { "target", "#music" },
76 { "message", "hello!" }
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-me" },
99 { "server", "" },
100 { "target", "#music" },
101 { "message", "hello!" }
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-me" },
124 { "server", "test" },
125 { "target", "" },
126 { "message", "hello!" }
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-me" },
149 { "server", "test" },
150 { "target", 123456 },
151 { "message", "hello!" }
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-me" },
174 { "server", "unknown" },
175 { "target", "#music" },
176 { "message", "hello!" }
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