1 | #include "includes.h" |
2 | #include "test_sink.h" |
3 | #include "spdlog/async.h" |
4 | |
5 | TEST_CASE("time_point1" , "[time_point log_msg]" ) |
6 | { |
7 | std::shared_ptr<spdlog::sinks::test_sink_st> test_sink(new spdlog::sinks::test_sink_st); |
8 | spdlog::logger logger("test-time_point" , test_sink); |
9 | |
10 | spdlog::source_loc source{}; |
11 | std::chrono::system_clock::time_point tp{std::chrono::system_clock::now()}; |
12 | test_sink->set_pattern("%T.%F" ); // interested in the time_point |
13 | |
14 | // all the following should have the same time |
15 | test_sink->set_delay(std::chrono::milliseconds(10)); |
16 | for (int i = 0; i < 5; i++) |
17 | { |
18 | spdlog::details::log_msg msg{tp, source, "test_logger" , spdlog::level::info, "message" }; |
19 | test_sink->log(msg); |
20 | } |
21 | |
22 | logger.log(tp, source, spdlog::level::info, "formatted message" ); |
23 | logger.log(tp, source, spdlog::level::info, "formatted message" ); |
24 | logger.log(tp, source, spdlog::level::info, "formatted message" ); |
25 | logger.log(tp, source, spdlog::level::info, "formatted message" ); |
26 | logger.log(source, spdlog::level::info, "formatted message" ); // last line has different time_point |
27 | |
28 | // now the real test... that the times are the same. |
29 | std::vector<std::string> lines = test_sink->lines(); |
30 | REQUIRE(lines[0] == lines[1]); |
31 | REQUIRE(lines[2] == lines[3]); |
32 | REQUIRE(lines[4] == lines[5]); |
33 | REQUIRE(lines[6] == lines[7]); |
34 | REQUIRE(lines[8] != lines[9]); |
35 | spdlog::drop_all(); |
36 | } |
37 | |