comparison tests/cmd-server-list/main.cpp @ 309:2f72a42ba595

Tests: add test for server-list, #559
author David Demelier <markand@malikania.fr>
date Wed, 19 Oct 2016 17:46:38 +0200
parents
children a6c3d73d9641
comparison
equal deleted inserted replaced
308:02b86903157f 309:2f72a42ba595
1 /*
2 * main.cpp -- test server-list 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-list.hpp>
20 #include <command-tester.hpp>
21 #include <server-tester.hpp>
22 #include <service-server.hpp>
23
24 using namespace irccd;
25 using namespace irccd::command;
26
27 namespace {
28
29 nlohmann::json result;
30
31 } // !namespace
32
33 class ServerListCommandTest : public CommandTester {
34 public:
35 ServerListCommandTest()
36 : CommandTester(std::make_unique<ServerListCommand>())
37 {
38 m_irccd.servers().add(std::make_unique<ServerTester>("s1"));
39 m_irccd.servers().add(std::make_unique<ServerTester>("s2"));
40 m_irccdctl.client().request({{ "command", "server-list" }});
41 m_irccdctl.client().onMessage.connect([&] (auto result) {
42 ::result = result;
43 });
44 }
45 };
46
47 TEST_F(ServerListCommandTest, basic)
48 {
49 try {
50 poll([&] () {
51 return result.is_object();
52 });
53
54 ASSERT_TRUE(result.is_object());
55 ASSERT_TRUE(result["list"].is_array());
56 ASSERT_EQ(2U, result["list"].size());
57 ASSERT_EQ("s1", result["list"][0]);
58 ASSERT_EQ("s2", result["list"][1]);
59 } catch (const std::exception &ex) {
60 FAIL() << ex.what();
61 }
62 }
63
64 int main(int argc, char **argv)
65 {
66 testing::InitGoogleTest(&argc, argv);
67
68 return RUN_ALL_TESTS();
69 }