spdlog
Loading...
Searching...
No Matches
tests
test_time_point.cpp
Go to the documentation of this file.
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
}
async.h
TEST_CASE
#define TEST_CASE(...)
Definition
catch.hpp:15119
REQUIRE
#define REQUIRE(...)
Definition
catch.hpp:15083
spdlog::logger
Definition
logger.h:48
spdlog::logger::log
void log(source_loc loc, level::level_enum lvl, fmt::format_string< Args... > fmt, Args &&...args)
Definition
logger.h:81
spdlog::sinks::test_sink
Definition
test_sink.h:20
std::chrono::milliseconds
includes.h
spdlog::level::info
@ info
Definition
common.h:165
spdlog::drop_all
SPDLOG_INLINE void drop_all()
Definition
spdlog-inl.h:95
std::chrono::system_clock::now
T now(T... args)
std::shared_ptr
spdlog::details::log_msg
Definition
log_msg.h:12
spdlog::source_loc
Definition
common.h:241
test_sink.h
std::vector
Generated by
1.9.8