comparison tests/src/plugin-ask/main.cpp @ 581:a51b5dd5b761

Tests: put everything in src/
author David Demelier <markand@malikania.fr>
date Mon, 04 Dec 2017 14:12:13 +0100
parents tests/plugin-ask/main.cpp@a5e1c91abb8e
children 35832b7f4f9d
comparison
equal deleted inserted replaced
580:2e16c3623531 581:a51b5dd5b761
1 /*
2 * main.cpp -- test ask plugin
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 "Ask plugin"
20 #include <boost/test/unit_test.hpp>
21
22 #include <irccd/irccd.hpp>
23 #include <irccd/server.hpp>
24
25 #include "plugin_test.hpp"
26
27 namespace irccd {
28
29 class ask_test : public plugin_test {
30 public:
31 inline ask_test()
32 : plugin_test(PLUGIN_NAME, PLUGIN_PATH)
33 {
34 plugin_->set_config({
35 { "file", CMAKE_CURRENT_SOURCE_DIR "/answers.conf" }
36 });
37 plugin_->on_load(irccd_);
38 }
39 };
40
41 BOOST_FIXTURE_TEST_SUITE(ask_test_suite, ask_test)
42
43 BOOST_AUTO_TEST_CASE(basic)
44 {
45 bool no = false;
46 bool yes = false;
47
48 /*
49 * Invoke the plugin 1000 times, it will be very unlucky to not have both
50 * answers in that amount of tries.
51 */
52 for (int i = 0; i < 1000; ++i) {
53 plugin_->on_command(irccd_, {server_, "tester", "#dummy", ""});
54
55 auto cmd = server_->cqueue().front();
56
57 BOOST_REQUIRE_EQUAL(cmd["command"].get<std::string>(), "message");
58 BOOST_REQUIRE_EQUAL(cmd["target"].get<std::string>(), "#dummy");
59
60 auto msg = cmd["message"].get<std::string>();
61
62 if (msg == "tester, YES")
63 yes = true;
64 if (msg == "tester, NO")
65 no = true;
66
67 server_->cqueue().clear();
68 }
69
70 BOOST_REQUIRE(no);
71 BOOST_REQUIRE(yes);
72 }
73
74 BOOST_AUTO_TEST_SUITE_END()
75
76 } // !irccd