]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #include <opentracing/util.h> |
2 | #include <cmath> | |
3 | #include <cstdlib> // Work around to https://stackoverflow.com/a/30084734. | |
4 | using namespace opentracing; | |
5 | ||
6 | #define CATCH_CONFIG_MAIN | |
7 | #include <opentracing/catch2/catch.hpp> | |
8 | ||
9 | TEST_CASE("convert_time_point") { | |
10 | SECTION("We can convert between time points of different clocks") { | |
11 | // Check that converting from a system_clock time_point to a steady_clock | |
12 | // time point and then back again produces approximately the same | |
13 | // system_clock time_point. | |
14 | auto t1 = SystemClock::now(); | |
15 | auto t2 = convert_time_point<SteadyClock>(t1); | |
16 | auto t3 = convert_time_point<SystemClock>(t2); | |
17 | auto difference = std::abs( | |
18 | std::chrono::duration_cast<std::chrono::microseconds>(t3 - t1).count()); | |
19 | CHECK(difference < 100); | |
20 | } | |
21 | ||
22 | SECTION("Converting times from the same clock gives the identity") { | |
23 | auto t = SystemClock::now(); | |
24 | CHECK(t == convert_time_point<SystemClock>(t)); | |
25 | } | |
26 | } |