comparison tests/src/libirccd/logger/main.cpp @ 611:9fbd1700435b

Tests: reoganize hierarchy
author David Demelier <markand@malikania.fr>
date Fri, 15 Dec 2017 15:37:58 +0100
parents tests/src/logger/main.cpp@e531f04507aa
children 27587ff92a64
comparison
equal deleted inserted replaced
610:22b3cd6f991f 611:9fbd1700435b
1 /*
2 * main.cpp -- test logger functions
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 #include <algorithm>
20
21 #define BOOST_TEST_MODULE "Logger"
22 #include <boost/test/unit_test.hpp>
23
24 #include <irccd/daemon/logger.hpp>
25
26 namespace irccd {
27
28 class my_logger : public logger {
29 public:
30 std::string line_debug;
31 std::string line_info;
32 std::string line_warning;
33
34 void write_debug(const std::string& line) override
35 {
36 line_debug = line;
37 }
38
39 void write_info(const std::string& line) override
40 {
41 line_info = line;
42 }
43
44 void write_warning(const std::string& line) override
45 {
46 line_warning = line;
47 }
48 };
49
50 class my_filter : public logger_filter {
51 public:
52 std::string pre_debug(std::string input) const override
53 {
54 return std::reverse(input.begin(), input.end()), input;
55 }
56
57 std::string pre_info(std::string input) const override
58 {
59 return std::reverse(input.begin(), input.end()), input;
60 }
61
62 std::string pre_warning(std::string input) const override
63 {
64 return std::reverse(input.begin(), input.end()), input;
65 }
66 };
67
68 class logger_test {
69 public:
70 my_logger log_;
71
72 logger_test()
73 {
74 log_.set_filter(std::make_unique<my_filter>());
75 log_.set_verbose(true);
76 }
77 };
78
79 BOOST_FIXTURE_TEST_SUITE(logger_test_suite, logger_test)
80
81 #if !defined(NDEBUG)
82
83 BOOST_AUTO_TEST_CASE(debug)
84 {
85 log_.debug("debug");
86
87 BOOST_REQUIRE_EQUAL("gubed", log_.line_debug);
88 }
89
90 #endif
91
92 BOOST_AUTO_TEST_CASE(info)
93 {
94 log_.info("info");
95
96 BOOST_REQUIRE_EQUAL("ofni", log_.line_info);
97 }
98
99 BOOST_AUTO_TEST_CASE(info_quiet)
100 {
101 log_.set_verbose(false);
102 log_.info("info");
103
104 BOOST_REQUIRE(log_.line_info.empty());
105 }
106
107 BOOST_AUTO_TEST_CASE(warning)
108 {
109 log_.warning("warning");
110
111 BOOST_REQUIRE_EQUAL("gninraw", log_.line_warning);
112 }
113
114 BOOST_AUTO_TEST_SUITE_END()
115
116 } // !irccd