diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/jaegertracing/opentelemetry-cpp/api/test/core | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/api/test/core')
3 files changed, 90 insertions, 0 deletions
diff --git a/src/jaegertracing/opentelemetry-cpp/api/test/core/BUILD b/src/jaegertracing/opentelemetry-cpp/api/test/core/BUILD new file mode 100644 index 000000000..99fcfaeca --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/api/test/core/BUILD @@ -0,0 +1,14 @@ +cc_test( + name = "timestamp_test", + srcs = [ + "timestamp_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/src/jaegertracing/opentelemetry-cpp/api/test/core/CMakeLists.txt b/src/jaegertracing/opentelemetry-cpp/api/test/core/CMakeLists.txt new file mode 100644 index 000000000..7fead491e --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/api/test/core/CMakeLists.txt @@ -0,0 +1,9 @@ +include(GoogleTest) + +add_executable(timestamp_test timestamp_test.cc) +target_link_libraries(timestamp_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +gtest_add_tests( + TARGET timestamp_test + TEST_PREFIX trace. + TEST_LIST timestamp_test) diff --git a/src/jaegertracing/opentelemetry-cpp/api/test/core/timestamp_test.cc b/src/jaegertracing/opentelemetry-cpp/api/test/core/timestamp_test.cc new file mode 100644 index 000000000..8efc0215b --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/api/test/core/timestamp_test.cc @@ -0,0 +1,67 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/common/timestamp.h" + +#include <gtest/gtest.h> + +using opentelemetry::common::SteadyTimestamp; +using opentelemetry::common::SystemTimestamp; + +template <class Timestamp> +static bool AreNearlyEqual(const Timestamp &t1, const Timestamp &t2) noexcept +{ + return std::abs(std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count()) < 2; +} + +TEST(SystemTimestampTest, Construction) +{ + auto now_system = std::chrono::system_clock::now(); + + SystemTimestamp t1; + EXPECT_EQ(t1.time_since_epoch(), std::chrono::nanoseconds{0}); + + SystemTimestamp t2{now_system}; + EXPECT_TRUE(AreNearlyEqual(now_system, static_cast<std::chrono::system_clock::time_point>(t2))); + EXPECT_EQ(std::chrono::duration_cast<std::chrono::nanoseconds>(now_system.time_since_epoch()), + t2.time_since_epoch()); +} + +TEST(SystemTimestampTest, Comparison) +{ + SystemTimestamp t1; + SystemTimestamp t2; + SystemTimestamp t3{std::chrono::nanoseconds{2}}; + + EXPECT_EQ(t1, t1); + EXPECT_EQ(t1, t2); + EXPECT_EQ(t2, t1); + EXPECT_NE(t1, t3); + EXPECT_NE(t3, t1); +} + +TEST(SteadyTimestampTest, Construction) +{ + auto now_steady = std::chrono::steady_clock::now(); + + SteadyTimestamp t1; + EXPECT_EQ(t1.time_since_epoch(), std::chrono::nanoseconds{0}); + + SteadyTimestamp t2{now_steady}; + EXPECT_TRUE(AreNearlyEqual(now_steady, static_cast<std::chrono::steady_clock::time_point>(t2))); + EXPECT_EQ(std::chrono::duration_cast<std::chrono::nanoseconds>(now_steady.time_since_epoch()), + t2.time_since_epoch()); +} + +TEST(SteadyTimestampTest, Comparison) +{ + SteadyTimestamp t1; + SteadyTimestamp t2; + SteadyTimestamp t3{std::chrono::nanoseconds{2}}; + + EXPECT_EQ(t1, t1); + EXPECT_EQ(t1, t2); + EXPECT_EQ(t2, t1); + EXPECT_NE(t1, t3); + EXPECT_NE(t3, t1); +} |