comparison tests/src/logger-jsapi/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/logger-jsapi/main.cpp@84ea13c850f4
children e531f04507aa
comparison
equal deleted inserted replaced
580:2e16c3623531 581:a51b5dd5b761
1 /*
2 * main.cpp -- test Irccd.Logger API
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 "Logger Javascript API"
20 #include <boost/test/unit_test.hpp>
21
22 #include <irccd/logger.hpp>
23
24 #include <irccd/js/logger_jsapi.hpp>
25 #include <irccd/js/plugin_jsapi.hpp>
26
27 #include <js_test.hpp>
28
29 namespace irccd {
30
31 class logger_test : public js_test<logger_jsapi, plugin_jsapi> {
32 protected:
33 std::string line_info;
34 std::string line_warning;
35 std::string line_debug;
36
37 class my_logger : public log::logger {
38 private:
39 logger_test& test_;
40
41 public:
42 inline my_logger(logger_test& test) noexcept
43 : test_(test)
44 {
45 }
46
47 void info(const std::string& line) override
48 {
49 test_.line_info = line;
50 }
51
52 void warning(const std::string& line) override
53 {
54 test_.line_warning = line;
55 }
56
57 void debug(const std::string& line) override
58 {
59 test_.line_debug = line;
60 }
61 };
62
63 logger_test()
64 {
65 log::set_verbose(true);
66 log::set_logger(std::make_unique<my_logger>(*this));
67 }
68 };
69
70 BOOST_FIXTURE_TEST_SUITE(logger_jsapi_suite, logger_test)
71
72 BOOST_AUTO_TEST_CASE(info)
73 {
74 if (duk_peval_string(plugin_->context(), "Irccd.Logger.info(\"hello!\");") != 0)
75 throw dukx_stack(plugin_->context(), -1);
76
77 BOOST_TEST("plugin test: hello!" == line_info);
78 }
79
80 BOOST_AUTO_TEST_CASE(warning)
81 {
82 if (duk_peval_string(plugin_->context(), "Irccd.Logger.warning(\"FAIL!\");") != 0)
83 throw dukx_stack(plugin_->context(), -1);
84
85 BOOST_TEST("plugin test: FAIL!" == line_warning);
86 }
87
88 #if !defined(NDEBUG)
89
90 BOOST_AUTO_TEST_CASE(debug)
91 {
92 if (duk_peval_string(plugin_->context(), "Irccd.Logger.debug(\"starting\");") != 0)
93 throw dukx_stack(plugin_->context(), -1);
94
95 BOOST_TEST("plugin test: starting" == line_debug);
96 }
97
98 #endif
99
100 BOOST_AUTO_TEST_SUITE_END()
101
102 } // !irccd