diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
commit | b196c6498d22e47bb9d0da0153068ec54eac7956 (patch) | |
tree | 1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /test/util_test.cpp | |
parent | Initial commit. (diff) | |
download | opentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.tar.xz opentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.zip |
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/util_test.cpp')
-rw-r--r-- | test/util_test.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/util_test.cpp b/test/util_test.cpp new file mode 100644 index 0000000..9c1e30d --- /dev/null +++ b/test/util_test.cpp @@ -0,0 +1,26 @@ +#include <opentracing/util.h> +#include <cmath> +#include <cstdlib> // Work around to https://stackoverflow.com/a/30084734. +using namespace opentracing; + +#define CATCH_CONFIG_MAIN +#include <opentracing/catch2/catch.hpp> + +TEST_CASE("convert_time_point") { + SECTION("We can convert between time points of different clocks") { + // Check that converting from a system_clock time_point to a steady_clock + // time point and then back again produces approximately the same + // system_clock time_point. + auto t1 = SystemClock::now(); + auto t2 = convert_time_point<SteadyClock>(t1); + auto t3 = convert_time_point<SystemClock>(t2); + auto difference = std::abs( + std::chrono::duration_cast<std::chrono::microseconds>(t3 - t1).count()); + CHECK(difference < 100); + } + + SECTION("Converting times from the same clock gives the identity") { + auto t = SystemClock::now(); + CHECK(t == convert_time_point<SystemClock>(t)); + } +} |