comparison tests/plugin-ask/main.cpp @ 489:349fe29d86d5

Tests: switch to Boost, closes #680
author David Demelier <markand@malikania.fr>
date Sun, 20 Aug 2017 08:16:39 +0200
parents 7e273b7f4f92
children a5e1c91abb8e
comparison
equal deleted inserted replaced
488:7e273b7f4f92 489:349fe29d86d5
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 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 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include <gtest/gtest.h> 19 #define BOOST_TEST_MODULE "Ask plugin"
20 #include <boost/test/unit_test.hpp>
20 21
21 #include <irccd/irccd.hpp> 22 #include <irccd/irccd.hpp>
22 #include <irccd/server.hpp> 23 #include <irccd/server.hpp>
23 #include <irccd/service.hpp> 24 #include <irccd/service.hpp>
24 25
25 #include "plugin_test.hpp" 26 #include "plugin_test.hpp"
26 27
27 using namespace irccd; 28 namespace irccd {
28
29 class server_test : public server {
30 private:
31 std::string last_;
32
33 public:
34 inline server_test()
35 : server("test")
36 {
37 }
38
39 inline const std::string& last() const noexcept
40 {
41 return last_;
42 }
43
44 void message(std::string target, std::string message) override
45 {
46 last_ = util::join({target, message});
47 }
48 };
49 29
50 class ask_test : public plugin_test { 30 class ask_test : public plugin_test {
51 protected:
52 std::shared_ptr<server_test> server_{new server_test};
53
54 public: 31 public:
55 inline ask_test() 32 inline ask_test()
56 : plugin_test(PLUGIN_NAME, PLUGIN_PATH) 33 : plugin_test(PLUGIN_NAME, PLUGIN_PATH)
57 { 34 {
58 plugin_->set_config({ 35 plugin_->set_config({
60 }); 37 });
61 plugin_->on_load(irccd_); 38 plugin_->on_load(irccd_);
62 } 39 }
63 }; 40 };
64 41
65 TEST_F(ask_test, basic) 42 BOOST_FIXTURE_TEST_SUITE(ask_test_suite, ask_test)
43
44 BOOST_AUTO_TEST_CASE(basic)
66 { 45 {
67 bool no = false; 46 bool no = false;
68 bool yes = false; 47 bool yes = false;
69 48
70 /* 49 /*
72 * answers in that amount of tries. 51 * answers in that amount of tries.
73 */ 52 */
74 for (int i = 0; i < 1000; ++i) { 53 for (int i = 0; i < 1000; ++i) {
75 plugin_->on_command(irccd_, {server_, "tester", "#dummy", ""}); 54 plugin_->on_command(irccd_, {server_, "tester", "#dummy", ""});
76 55
77 if (server_->last() == "#dummy:tester, YES") 56 auto cmd = server_->cqueue().front();
57
58 BOOST_REQUIRE_EQUAL(cmd["command"].get<std::string>(), "message");
59 BOOST_REQUIRE_EQUAL(cmd["target"].get<std::string>(), "#dummy");
60
61 auto msg = cmd["message"].get<std::string>();
62
63 if (msg == "tester, YES")
78 yes = true; 64 yes = true;
79 if (server_->last() == "#dummy:tester, NO") 65 if (msg == "tester, NO")
80 no = true; 66 no = true;
67
68 server_->cqueue().clear();
81 } 69 }
82 70
83 ASSERT_TRUE(no); 71 BOOST_REQUIRE(no);
84 ASSERT_TRUE(yes); 72 BOOST_REQUIRE(yes);
85 } 73 }
86 74
87 int main(int argc, char** argv) 75 BOOST_AUTO_TEST_SUITE_END()
88 {
89 testing::InitGoogleTest(&argc, argv);
90 76
91 return RUN_ALL_TESTS(); 77 } // !irccd
92 }