Mercurial > irccd
comparison tests/src/libirccd/logger/main.cpp @ 773:8c44bbcbbab9
Misc: style, cleanup and update
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 26 Oct 2018 13:01:00 +0200 |
parents | 0dbe1842a7d8 |
children |
comparison
equal
deleted
inserted
replaced
772:f5ccf65ae929 | 773:8c44bbcbbab9 |
---|---|
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 class sample_sink : public logger::sink { | 34 class sample_sink : public logger::sink { |
35 public: | 35 public: |
36 std::string line_debug; | 36 std::string line_debug; |
37 std::string line_info; | 37 std::string line_info; |
38 std::string line_warning; | 38 std::string line_warning; |
39 | 39 |
40 void write_debug(const std::string& line) override | 40 void write_debug(const std::string& line) override |
41 { | 41 { |
42 line_debug = line; | 42 line_debug = line; |
43 } | 43 } |
44 | 44 |
45 void write_info(const std::string& line) override | 45 void write_info(const std::string& line) override |
46 { | 46 { |
47 line_info = line; | 47 line_info = line; |
48 } | 48 } |
49 | 49 |
50 void write_warning(const std::string& line) override | 50 void write_warning(const std::string& line) override |
51 { | 51 { |
52 line_warning = line; | 52 line_warning = line; |
53 } | 53 } |
54 }; | 54 }; |
55 | 55 |
56 class sample_filter : public logger::filter { | 56 class sample_filter : public logger::filter { |
57 public: | 57 public: |
58 auto pre_debug(std::string_view category, | 58 auto pre_debug(std::string_view category, |
59 std::string_view component, | 59 std::string_view component, |
60 std::string_view message) const -> std::string override | 60 std::string_view message) const -> std::string override |
61 { | 61 { |
62 return str(format("DEBUG %s:%s:%s") % category % component % message); | 62 return str(format("DEBUG %s:%s:%s") % category % component % message); |
63 } | 63 } |
64 | 64 |
65 auto pre_info(std::string_view category, | 65 auto pre_info(std::string_view category, |
66 std::string_view component, | 66 std::string_view component, |
67 std::string_view message) const -> std::string override | 67 std::string_view message) const -> std::string override |
68 { | 68 { |
69 return str(format("INFO %s:%s:%s") % category % component % message); | 69 return str(format("INFO %s:%s:%s") % category % component % message); |
70 } | 70 } |
71 | 71 |
72 auto pre_warning(std::string_view category, | 72 auto pre_warning(std::string_view category, |
73 std::string_view component, | 73 std::string_view component, |
74 std::string_view message) const -> std::string override | 74 std::string_view message) const -> std::string override |
75 { | 75 { |
76 return str(format("WARN %s:%s:%s") % category % component % message); | 76 return str(format("WARN %s:%s:%s") % category % component % message); |
77 } | 77 } |
78 }; | 78 }; |
79 | 79 |
80 class logger_test { | 80 class logger_test { |
81 public: | 81 public: |
82 sample_sink log_; | 82 sample_sink log_; |
83 | 83 |
84 logger_test() | 84 logger_test() |
85 { | 85 { |
86 log_.set_filter(std::make_unique<sample_filter>()); | 86 log_.set_filter(std::make_unique<sample_filter>()); |
87 log_.set_verbose(true); | 87 log_.set_verbose(true); |
88 } | 88 } |
89 }; | 89 }; |
90 | 90 |
91 BOOST_FIXTURE_TEST_SUITE(logger_test_suite, logger_test) | 91 BOOST_FIXTURE_TEST_SUITE(logger_test_suite, logger_test) |
92 | 92 |
93 #if !defined(NDEBUG) | 93 #if !defined(NDEBUG) |
94 | 94 |
95 BOOST_AUTO_TEST_CASE(debug) | 95 BOOST_AUTO_TEST_CASE(debug) |
96 { | 96 { |
97 log_.debug("test", "debug") << "success" << std::endl; | 97 log_.debug("test", "debug") << "success" << std::endl; |
98 | 98 |
99 BOOST_TEST(log_.line_debug == "DEBUG test:debug:success"); | 99 BOOST_TEST(log_.line_debug == "DEBUG test:debug:success"); |
100 } | 100 } |
101 | 101 |
102 #endif | 102 #endif |
103 | 103 |
104 BOOST_AUTO_TEST_CASE(info) | 104 BOOST_AUTO_TEST_CASE(info) |
105 { | 105 { |
106 log_.info("test", "info") << "success" << std::endl; | 106 log_.info("test", "info") << "success" << std::endl; |
107 | 107 |
108 BOOST_TEST(log_.line_info == "INFO test:info:success"); | 108 BOOST_TEST(log_.line_info == "INFO test:info:success"); |
109 } | 109 } |
110 | 110 |
111 BOOST_AUTO_TEST_CASE(info_quiet) | 111 BOOST_AUTO_TEST_CASE(info_quiet) |
112 { | 112 { |
113 log_.set_verbose(false); | 113 log_.set_verbose(false); |
114 log_.info("test", "info") << "success" << std::endl; | 114 log_.info("test", "info") << "success" << std::endl; |
115 | 115 |
116 BOOST_REQUIRE(log_.line_info.empty()); | 116 BOOST_REQUIRE(log_.line_info.empty()); |
117 } | 117 } |
118 | 118 |
119 BOOST_AUTO_TEST_CASE(warning) | 119 BOOST_AUTO_TEST_CASE(warning) |
120 { | 120 { |
121 log_.warning("test", "warning") << "success" << std::endl; | 121 log_.warning("test", "warning") << "success" << std::endl; |
122 | 122 |
123 BOOST_TEST(log_.line_warning == "WARN test:warning:success"); | 123 BOOST_TEST(log_.line_warning == "WARN test:warning:success"); |
124 } | 124 } |
125 | 125 |
126 BOOST_AUTO_TEST_SUITE_END() | 126 BOOST_AUTO_TEST_SUITE_END() |
127 | 127 |
128 } // !namespace | 128 } // !namespace |