Mercurial > irccd
comparison tests/src/libirccd/command-server-connect/main.cpp @ 773:8c44bbcbbab9
Misc: style, cleanup and update
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 26 Oct 2018 13:01:00 +0200 |
parents | 35c1517d705d |
children | 7145a3df4cb7 |
comparison
equal
deleted
inserted
replaced
772:f5ccf65ae929 | 773:8c44bbcbbab9 |
---|---|
29 | 29 |
30 BOOST_FIXTURE_TEST_SUITE(server_connect_fixture_suite, command_fixture) | 30 BOOST_FIXTURE_TEST_SUITE(server_connect_fixture_suite, command_fixture) |
31 | 31 |
32 BOOST_AUTO_TEST_CASE(minimal) | 32 BOOST_AUTO_TEST_CASE(minimal) |
33 { | 33 { |
34 const auto [json, code] = request({ | 34 const auto [json, code] = request({ |
35 { "command", "server-connect" }, | 35 { "command", "server-connect" }, |
36 { "name", "local" }, | 36 { "name", "local" }, |
37 { "host", "irc.example.org" } | 37 { "host", "irc.example.org" } |
38 }); | 38 }); |
39 | 39 |
40 const auto s = irccd_.servers().get("local"); | 40 const auto s = irccd_.servers().get("local"); |
41 | 41 |
42 BOOST_TEST(!code); | 42 BOOST_TEST(!code); |
43 BOOST_TEST(s); | 43 BOOST_TEST(s); |
44 BOOST_TEST(s->get_id() == "local"); | 44 BOOST_TEST(s->get_id() == "local"); |
45 BOOST_TEST(s->get_host() == "irc.example.org"); | 45 BOOST_TEST(s->get_host() == "irc.example.org"); |
46 BOOST_TEST(s->get_port() == 6667U); | 46 BOOST_TEST(s->get_port() == 6667U); |
47 } | 47 } |
48 | 48 |
49 #if defined(IRCCD_HAVE_SSL) | 49 #if defined(IRCCD_HAVE_SSL) |
50 | 50 |
51 BOOST_AUTO_TEST_CASE(full) | 51 BOOST_AUTO_TEST_CASE(full) |
52 { | 52 { |
53 const auto [json, code] = request({ | 53 const auto [json, code] = request({ |
54 { "command", "server-connect" }, | 54 { "command", "server-connect" }, |
55 { "name", "local2" }, | 55 { "name", "local2" }, |
56 { "host", "irc.example2.org" }, | 56 { "host", "irc.example2.org" }, |
57 { "password", "nonono" }, | 57 { "password", "nonono" }, |
58 { "nickname", "francis" }, | 58 { "nickname", "francis" }, |
59 { "realname", "the_francis" }, | 59 { "realname", "the_francis" }, |
60 { "username", "frc" }, | 60 { "username", "frc" }, |
61 { "ctcpVersion", "ultra bot" }, | 61 { "ctcpVersion", "ultra bot" }, |
62 { "commandChar", "::" }, | 62 { "commandChar", "::" }, |
63 { "port", 18000 }, | 63 { "port", 18000 }, |
64 { "ssl", true }, | 64 { "ssl", true }, |
65 { "sslVerify", true }, | 65 { "sslVerify", true }, |
66 { "autoRejoin", true }, | 66 { "autoRejoin", true }, |
67 { "joinInvite", true } | 67 { "joinInvite", true } |
68 }); | 68 }); |
69 | 69 |
70 const auto s = irccd_.servers().get("local2"); | 70 const auto s = irccd_.servers().get("local2"); |
71 | 71 |
72 BOOST_TEST(!code); | 72 BOOST_TEST(!code); |
73 BOOST_TEST(s); | 73 BOOST_TEST(s); |
74 BOOST_TEST(s->get_id() == "local2"); | 74 BOOST_TEST(s->get_id() == "local2"); |
75 BOOST_TEST(s->get_host() == "irc.example2.org"); | 75 BOOST_TEST(s->get_host() == "irc.example2.org"); |
76 BOOST_TEST(s->get_port() == 18000U); | 76 BOOST_TEST(s->get_port() == 18000U); |
77 BOOST_TEST(s->get_password() == "nonono"); | 77 BOOST_TEST(s->get_password() == "nonono"); |
78 BOOST_TEST(s->get_nickname() == "francis"); | 78 BOOST_TEST(s->get_nickname() == "francis"); |
79 BOOST_TEST(s->get_realname() == "the_francis"); | 79 BOOST_TEST(s->get_realname() == "the_francis"); |
80 BOOST_TEST(s->get_username() == "frc"); | 80 BOOST_TEST(s->get_username() == "frc"); |
81 BOOST_TEST(s->get_command_char() == "::"); | 81 BOOST_TEST(s->get_command_char() == "::"); |
82 BOOST_TEST(s->get_ctcp_version() == "ultra bot"); | 82 BOOST_TEST(s->get_ctcp_version() == "ultra bot"); |
83 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::ssl)); | 83 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::ssl)); |
84 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::ssl_verify)); | 84 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::ssl_verify)); |
85 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::auto_rejoin)); | 85 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::auto_rejoin)); |
86 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::join_invite)); | 86 BOOST_TEST(static_cast<bool>(s->get_options() & server::options::join_invite)); |
87 } | 87 } |
88 | 88 |
89 #endif // !IRCCD_HAVE_SSL | 89 #endif // !IRCCD_HAVE_SSL |
90 | 90 |
91 BOOST_AUTO_TEST_SUITE(errors) | 91 BOOST_AUTO_TEST_SUITE(errors) |
92 | 92 |
93 BOOST_AUTO_TEST_CASE(already_exists) | 93 BOOST_AUTO_TEST_CASE(already_exists) |
94 { | 94 { |
95 irccd_.servers().add(std::make_unique<mock_server>(ctx_, "local")); | 95 irccd_.servers().add(std::make_unique<mock_server>(ctx_, "local")); |
96 | 96 |
97 const auto [json, code] = request({ | 97 const auto [json, code] = request({ |
98 { "command", "server-connect" }, | 98 { "command", "server-connect" }, |
99 { "name", "local" }, | 99 { "name", "local" }, |
100 { "host", "127.0.0.1" } | 100 { "host", "127.0.0.1" } |
101 }); | 101 }); |
102 | 102 |
103 BOOST_TEST(code == server_error::already_exists); | 103 BOOST_TEST(code == server_error::already_exists); |
104 BOOST_TEST(json["error"].get<int>() == server_error::already_exists); | 104 BOOST_TEST(json["error"].get<int>() == server_error::already_exists); |
105 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 105 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
106 } | 106 } |
107 | 107 |
108 BOOST_AUTO_TEST_CASE(invalid_hostname_1) | 108 BOOST_AUTO_TEST_CASE(invalid_hostname_1) |
109 { | 109 { |
110 const auto [json, code] = request({ | 110 const auto [json, code] = request({ |
111 { "command", "server-connect" }, | 111 { "command", "server-connect" }, |
112 { "name", "new" }, | 112 { "name", "new" }, |
113 }); | 113 }); |
114 | 114 |
115 BOOST_TEST(code == server_error::invalid_hostname); | 115 BOOST_TEST(code == server_error::invalid_hostname); |
116 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); | 116 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); |
117 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 117 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
118 } | 118 } |
119 | 119 |
120 BOOST_AUTO_TEST_CASE(invalid_hostname_2) | 120 BOOST_AUTO_TEST_CASE(invalid_hostname_2) |
121 { | 121 { |
122 const auto [json, code] = request({ | 122 const auto [json, code] = request({ |
123 { "command", "server-connect" }, | 123 { "command", "server-connect" }, |
124 { "name", "new" }, | 124 { "name", "new" }, |
125 { "host", 123456 } | 125 { "host", 123456 } |
126 }); | 126 }); |
127 | 127 |
128 BOOST_TEST(code == server_error::invalid_hostname); | 128 BOOST_TEST(code == server_error::invalid_hostname); |
129 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); | 129 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); |
130 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 130 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
131 } | 131 } |
132 | 132 |
133 BOOST_AUTO_TEST_CASE(invalid_identifier_1) | 133 BOOST_AUTO_TEST_CASE(invalid_identifier_1) |
134 { | 134 { |
135 const auto [json, code] = request({ | 135 const auto [json, code] = request({ |
136 { "command", "server-connect" }, | 136 { "command", "server-connect" }, |
137 { "name", "" }, | 137 { "name", "" }, |
138 { "host", "127.0.0.1" } | 138 { "host", "127.0.0.1" } |
139 }); | 139 }); |
140 | 140 |
141 BOOST_TEST(code == server_error::invalid_identifier); | 141 BOOST_TEST(code == server_error::invalid_identifier); |
142 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); | 142 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); |
143 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 143 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
144 } | 144 } |
145 | 145 |
146 BOOST_AUTO_TEST_CASE(invalid_identifier_2) | 146 BOOST_AUTO_TEST_CASE(invalid_identifier_2) |
147 { | 147 { |
148 const auto [json, code] = request({ | 148 const auto [json, code] = request({ |
149 { "command", "server-connect" }, | 149 { "command", "server-connect" }, |
150 { "name", 123456 }, | 150 { "name", 123456 }, |
151 { "host", "127.0.0.1" } | 151 { "host", "127.0.0.1" } |
152 }); | 152 }); |
153 | 153 |
154 BOOST_TEST(code == server_error::invalid_identifier); | 154 BOOST_TEST(code == server_error::invalid_identifier); |
155 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); | 155 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); |
156 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 156 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
157 } | 157 } |
158 | 158 |
159 BOOST_AUTO_TEST_CASE(invalid_port_1) | 159 BOOST_AUTO_TEST_CASE(invalid_port_1) |
160 { | 160 { |
161 const auto [json, code] = request({ | 161 const auto [json, code] = request({ |
162 { "command", "server-connect" }, | 162 { "command", "server-connect" }, |
163 { "name", "new" }, | 163 { "name", "new" }, |
164 { "host", "127.0.0.1" }, | 164 { "host", "127.0.0.1" }, |
165 { "port", "notaint" } | 165 { "port", "notaint" } |
166 }); | 166 }); |
167 | 167 |
168 BOOST_TEST(code == server_error::invalid_port); | 168 BOOST_TEST(code == server_error::invalid_port); |
169 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); | 169 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
170 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 170 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
171 } | 171 } |
172 | 172 |
173 BOOST_AUTO_TEST_CASE(invalid_port_2) | 173 BOOST_AUTO_TEST_CASE(invalid_port_2) |
174 { | 174 { |
175 const auto [json, code] = request({ | 175 const auto [json, code] = request({ |
176 { "command", "server-connect" }, | 176 { "command", "server-connect" }, |
177 { "name", "new" }, | 177 { "name", "new" }, |
178 { "host", "127.0.0.1" }, | 178 { "host", "127.0.0.1" }, |
179 { "port", -123 } | 179 { "port", -123 } |
180 }); | 180 }); |
181 | 181 |
182 BOOST_TEST(code == server_error::invalid_port); | 182 BOOST_TEST(code == server_error::invalid_port); |
183 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); | 183 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
184 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 184 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
185 } | 185 } |
186 | 186 |
187 BOOST_AUTO_TEST_CASE(invalid_port_3) | 187 BOOST_AUTO_TEST_CASE(invalid_port_3) |
188 { | 188 { |
189 const auto [json, code] = request({ | 189 const auto [json, code] = request({ |
190 { "command", "server-connect" }, | 190 { "command", "server-connect" }, |
191 { "name", "new" }, | 191 { "name", "new" }, |
192 { "host", "127.0.0.1" }, | 192 { "host", "127.0.0.1" }, |
193 { "port", 1000000 } | 193 { "port", 1000000 } |
194 }); | 194 }); |
195 | 195 |
196 BOOST_TEST(code == server_error::invalid_port); | 196 BOOST_TEST(code == server_error::invalid_port); |
197 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); | 197 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
198 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 198 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
199 } | 199 } |
200 | 200 |
201 #if !defined(IRCCD_HAVE_SSL) | 201 #if !defined(IRCCD_HAVE_SSL) |
202 | 202 |
203 BOOST_AUTO_TEST_CASE(ssl_disabled) | 203 BOOST_AUTO_TEST_CASE(ssl_disabled) |
204 { | 204 { |
205 const auto [json, code] = request({ | 205 const auto [json, code] = request({ |
206 { "command", "server-connect" }, | 206 { "command", "server-connect" }, |
207 { "name", "new" }, | 207 { "name", "new" }, |
208 { "host", "127.0.0.1" }, | 208 { "host", "127.0.0.1" }, |
209 { "ssl", true } | 209 { "ssl", true } |
210 }); | 210 }); |
211 | 211 |
212 BOOST_TEST(code == server_error::ssl_disabled); | 212 BOOST_TEST(code == server_error::ssl_disabled); |
213 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled); | 213 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled); |
214 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 214 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
215 } | 215 } |
216 | 216 |
217 #endif | 217 #endif |
218 | 218 |
219 BOOST_AUTO_TEST_SUITE_END() | 219 BOOST_AUTO_TEST_SUITE_END() |