|
1 | 1 | #include "includes.h" |
2 | 2 | #include "test_sink.h" |
3 | | -#include "spdlog/fmt/bin_to_hex.h" |
4 | 3 |
|
5 | 4 | template<class T> |
6 | 5 | std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info) |
@@ -140,96 +139,6 @@ TEST_CASE("clone async", "[clone]") |
140 | 139 | spdlog::drop_all(); |
141 | 140 | } |
142 | 141 |
|
143 | | -TEST_CASE("to_hex", "[to_hex]") |
144 | | -{ |
145 | | - std::ostringstream oss; |
146 | | - auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); |
147 | | - spdlog::logger oss_logger("oss", oss_sink); |
148 | | - |
149 | | - std::vector<unsigned char> v{9, 0xa, 0xb, 0xc, 0xff, 0xff}; |
150 | | - oss_logger.info("{}", spdlog::to_hex(v)); |
151 | | - |
152 | | - auto output = oss.str(); |
153 | | - REQUIRE(ends_with(output, "0000: 09 0a 0b 0c ff ff" + std::string(spdlog::details::os::default_eol))); |
154 | | -} |
155 | | - |
156 | | -TEST_CASE("to_hex_upper", "[to_hex]") |
157 | | -{ |
158 | | - std::ostringstream oss; |
159 | | - auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); |
160 | | - spdlog::logger oss_logger("oss", oss_sink); |
161 | | - |
162 | | - std::vector<unsigned char> v{9, 0xa, 0xb, 0xc, 0xff, 0xff}; |
163 | | - oss_logger.info("{:X}", spdlog::to_hex(v)); |
164 | | - |
165 | | - auto output = oss.str(); |
166 | | - REQUIRE(ends_with(output, "0000: 09 0A 0B 0C FF FF" + std::string(spdlog::details::os::default_eol))); |
167 | | -} |
168 | | - |
169 | | -TEST_CASE("to_hex_no_delimiter", "[to_hex]") |
170 | | -{ |
171 | | - std::ostringstream oss; |
172 | | - auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); |
173 | | - spdlog::logger oss_logger("oss", oss_sink); |
174 | | - |
175 | | - std::vector<unsigned char> v{9, 0xa, 0xb, 0xc, 0xff, 0xff}; |
176 | | - oss_logger.info("{:sX}", spdlog::to_hex(v)); |
177 | | - |
178 | | - auto output = oss.str(); |
179 | | - REQUIRE(ends_with(output, "0000: 090A0B0CFFFF" + std::string(spdlog::details::os::default_eol))); |
180 | | -} |
181 | | - |
182 | | -TEST_CASE("to_hex_show_ascii", "[to_hex]") |
183 | | -{ |
184 | | - std::ostringstream oss; |
185 | | - auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); |
186 | | - spdlog::logger oss_logger("oss", oss_sink); |
187 | | - |
188 | | - std::vector<unsigned char> v{9, 0xa, 0xb, 0x41, 0xc, 0x4b, 0xff, 0xff}; |
189 | | - oss_logger.info("{:Xsa}", spdlog::to_hex(v, 8)); |
190 | | - |
191 | | - REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF ...A.K.." + std::string(spdlog::details::os::default_eol))); |
192 | | -} |
193 | | - |
194 | | -TEST_CASE("to_hex_different_size_per_line", "[to_hex]") |
195 | | -{ |
196 | | - std::ostringstream oss; |
197 | | - auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); |
198 | | - spdlog::logger oss_logger("oss", oss_sink); |
199 | | - |
200 | | - std::vector<unsigned char> v{9, 0xa, 0xb, 0x41, 0xc, 0x4b, 0xff, 0xff}; |
201 | | - |
202 | | - oss_logger.info("{:Xsa}", spdlog::to_hex(v, 10)); |
203 | | - REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF ...A.K.." + std::string(spdlog::details::os::default_eol))); |
204 | | - |
205 | | - oss_logger.info("{:Xs}", spdlog::to_hex(v, 10)); |
206 | | - REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol))); |
207 | | - |
208 | | - oss_logger.info("{:Xsa}", spdlog::to_hex(v, 6)); |
209 | | - REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4B ...A.K" + std::string(spdlog::details::os::default_eol) + "0006: FFFF .." + |
210 | | - std::string(spdlog::details::os::default_eol))); |
211 | | - |
212 | | - oss_logger.info("{:Xs}", spdlog::to_hex(v, 6)); |
213 | | - REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4B" + std::string(spdlog::details::os::default_eol) + "0006: FFFF" + |
214 | | - std::string(spdlog::details::os::default_eol))); |
215 | | -} |
216 | | - |
217 | | -TEST_CASE("to_hex_no_ascii", "[to_hex]") |
218 | | -{ |
219 | | - std::ostringstream oss; |
220 | | - auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); |
221 | | - spdlog::logger oss_logger("oss", oss_sink); |
222 | | - |
223 | | - std::vector<unsigned char> v{9, 0xa, 0xb, 0x41, 0xc, 0x4b, 0xff, 0xff}; |
224 | | - oss_logger.info("{:Xs}", spdlog::to_hex(v, 8)); |
225 | | - |
226 | | - REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol))); |
227 | | - |
228 | | - oss_logger.info("{:Xsna}", spdlog::to_hex(v, 8)); |
229 | | - |
230 | | - REQUIRE(ends_with(oss.str(), "090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol))); |
231 | | -} |
232 | | - |
233 | 142 | TEST_CASE("default logger API", "[default logger]") |
234 | 143 | { |
235 | 144 | std::ostringstream oss; |
|
0 commit comments