spdlog
Loading...
Searching...
No Matches
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
5TEST_CASE("stopwatch1", "[stopwatch]")
6{
8 milliseconds wait_ms(250);
9 milliseconds tolerance_ms(250);
10
13 REQUIRE(sw.elapsed() >= wait_ms);
14 REQUIRE(sw.elapsed() <= wait_ms + tolerance_ms);
15}
16
17TEST_CASE("stopwatch2", "[stopwatch]")
18{
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
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}
#define TEST_CASE(...)
Definition catch.hpp:15119
#define REQUIRE(...)
Definition catch.hpp:15083
void info(fmt::format_string< Args... > fmt, Args &&...args)
Definition logger.h:156
void set_pattern(std::string pattern, pattern_time_type time_type=pattern_time_type::local)
Definition logger-inl.h:101
std::chrono::duration< double > elapsed() const
Definition stopwatch.h:38
constexpr auto count() -> size_t
Definition core.h:1039
T make_shared(T... args)
T sleep_for(T... args)
T stod(T... args)