From e81e3e0fff67706493e3cfec7d30391ce6145de9 Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Mon, 7 Oct 2024 13:49:33 +0200 Subject: [PATCH] test - introduce unit tests for telemetry::Symlink --- src/telemetry/symlink.cpp | 4 +++ src/telemetry/tests/testSymlink.cpp | 52 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/telemetry/tests/testSymlink.cpp diff --git a/src/telemetry/symlink.cpp b/src/telemetry/symlink.cpp index 0a62a29..39f4746 100644 --- a/src/telemetry/symlink.cpp +++ b/src/telemetry/symlink.cpp @@ -29,3 +29,7 @@ Symlink::Symlink( } } // namespace telemetry + +#ifdef TELEMETRY_ENABLE_TESTS +#include "tests/testSymlink.cpp" +#endif diff --git a/src/telemetry/tests/testSymlink.cpp b/src/telemetry/tests/testSymlink.cpp new file mode 100644 index 0000000..247c20d --- /dev/null +++ b/src/telemetry/tests/testSymlink.cpp @@ -0,0 +1,52 @@ +/** + * @file + * @author Pavel Siska + * @brief Unit tests of telemetry::File class + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include + +namespace telemetry { + +/** + * @test Test checking symlink target + */ +TEST(TelemetrySymlink, hasTarget) +{ + auto root = Directory::create(); + auto dir = root->addDir("dir"); + auto file = dir->addFile("file", {}); + auto symlink = root->addSymlink("symlink", file); + + auto target = symlink->getTarget(); + + EXPECT_EQ(file, target); +} + +/** + * @test Test checking symlink target lifetime + */ +TEST(TelemetrySymlink, targetScopeLifetime) +{ + auto root = Directory::create(); + auto dir = root->addDir("dir"); + + std::shared_ptr symlink; + + { + auto file = dir->addFile("file", {}); + symlink = root->addSymlink("symlink", file); + + auto target = symlink->getTarget(); + EXPECT_EQ(file, target); + } + + auto target = symlink->getTarget(); + EXPECT_EQ(nullptr, target); +} + +} // namespace telemetry