comparison tests/cmd-server-join/main.cpp @ 307:2fa974c03282

Tests: add test for server-join, #559
author David Demelier <markand@malikania.fr>
date Wed, 19 Oct 2016 18:04:57 +0200
parents
children a6c3d73d9641
comparison
equal deleted inserted replaced
306:c6eed76f8646 307:2fa974c03282
1 /*
2 * main.cpp -- test server-join remote command
3 *
4 * Copyright (c) 2013-2016 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 #include <cmd-server-join.hpp>
20 #include <command-tester.hpp>
21 #include <server-tester.hpp>
22
23 using namespace irccd;
24 using namespace irccd::command;
25
26 namespace {
27
28 std::string channel;
29 std::string password;
30
31 } // !namespace
32
33 class ServerJoinTest : public ServerTester {
34 public:
35 void join(std::string channel, std::string password) override
36 {
37 ::channel = channel;
38 ::password = password;
39 }
40 };
41
42 class ServerJoinCommandTest : public CommandTester {
43 public:
44 ServerJoinCommandTest()
45 : CommandTester(std::make_unique<ServerJoinCommand>(),
46 std::make_unique<ServerJoinTest>())
47 {
48 channel.clear();
49 password.clear();
50
51
52 }
53 };
54
55 TEST_F(ServerJoinCommandTest, basic)
56 {
57 try {
58 m_irccdctl.client().request({
59 { "command", "server-join" },
60 { "server", "test" },
61 { "channel", "#music" },
62 { "password", "plop" }
63 });
64
65 poll([&] () {
66 return !channel.empty();
67 });
68
69 ASSERT_EQ("#music", channel);
70 ASSERT_EQ("plop", password);
71 } catch (const std::exception &ex) {
72 FAIL() << ex.what();
73 }
74 }
75
76 TEST_F(ServerJoinCommandTest, nopassword)
77 {
78 try {
79 m_irccdctl.client().request({
80 { "command", "server-join" },
81 { "server", "test" },
82 { "channel", "#music" }
83 });
84
85 poll([&] () {
86 return !channel.empty();
87 });
88
89 ASSERT_EQ("#music", channel);
90 ASSERT_EQ("", password);
91 } catch (const std::exception &ex) {
92 FAIL() << ex.what();
93 }
94 }
95
96 int main(int argc, char **argv)
97 {
98 testing::InitGoogleTest(&argc, argv);
99
100 return RUN_ALL_TESTS();
101 }