spdlog
Loading...
Searching...
No Matches
tests
test_stopwatch.cpp
Go to the documentation of this file.
1
#include "
includes.h
"
2
#include "
test_sink.h
"
3
#include "
spdlog/stopwatch.h
"
4
5
TEST_CASE
(
"stopwatch1"
,
"[stopwatch]"
)
6
{
7
using
std::chrono::milliseconds
;
8
milliseconds wait_ms(250);
9
milliseconds tolerance_ms(250);
10
11
spdlog::stopwatch
sw;
12
std::this_thread::sleep_for
(wait_ms);
13
REQUIRE
(sw.
elapsed
() >= wait_ms);
14
REQUIRE
(sw.
elapsed
() <= wait_ms + tolerance_ms);
15
}
16
17
TEST_CASE
(
"stopwatch2"
,
"[stopwatch]"
)
18
{
19
using
spdlog::sinks::test_sink_st
;
20
21
std::chrono::duration<double>
wait_duration(0.250);
22
std::chrono::duration<double>
tolerance_duration(0.250);
23
24
auto
test_sink =
std::make_shared<test_sink_st>
();
25
26
spdlog::stopwatch
sw;
27
spdlog::logger
logger(
"test-stopwatch"
, test_sink);
28
logger.
set_pattern
(
"%v"
);
29
std::this_thread::sleep_for
(wait_duration);
30
logger.
info
(
"{}"
, sw);
31
auto
val =
std::stod
(test_sink->lines()[0]);
32
33
REQUIRE
(val >= wait_duration.
count
());
34
REQUIRE
(val <= (wait_duration + tolerance_duration).
count
());
35
}
TEST_CASE
#define TEST_CASE(...)
Definition
catch.hpp:15119
REQUIRE
#define REQUIRE(...)
Definition
catch.hpp:15083
spdlog::logger
Definition
logger.h:48
spdlog::logger::info
void info(fmt::format_string< Args... > fmt, Args &&...args)
Definition
logger.h:156
spdlog::logger::set_pattern
void set_pattern(std::string pattern, pattern_time_type time_type=pattern_time_type::local)
Definition
logger-inl.h:101
spdlog::sinks::test_sink
Definition
test_sink.h:20
spdlog::stopwatch
Definition
stopwatch.h:29
spdlog::stopwatch::elapsed
std::chrono::duration< double > elapsed() const
Definition
stopwatch.h:38
count
constexpr auto count() -> size_t
Definition
core.h:1039
std::chrono::duration::count
T count(T... args)
std::chrono::milliseconds
includes.h
std::make_shared
T make_shared(T... args)
std::this_thread::sleep_for
T sleep_for(T... args)
std::stod
T stod(T... args)
stopwatch.h
test_sink.h
Generated by
1.9.8