File: util_test.cpp

package info (click to toggle)
opentracing-cpp 1.6.0-4.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,572 kB
  • sloc: cpp: 14,234; ansic: 68; sh: 16; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 949 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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));
  }
}