Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use relative path for model information #1399

Merged
merged 10 commits into from
Oct 3, 2024
Prev Previous commit
Next Next commit
chore: unit tests
  • Loading branch information
vansangpfiev committed Oct 3, 2024
commit 2484798d5387c47fdec1520daa18113110da0475
57 changes: 57 additions & 0 deletions engine/test/components/test_paths.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "gtest/gtest.h"
#include "utils/file_manager_utils.h"

namespace file_manager_utils {
// Test suite
class PathTests : public ::testing::Test {};

// Test cases for GetAbsolutePath
TEST_F(PathTests, GetAbsolutePath_AbsolutePath_ReturnsSamePath) {
auto base = std::filesystem::path("/base");
auto relative = std::filesystem::path("/absolute/path");
EXPECT_EQ(GetAbsolutePath(base, relative), relative);
}

TEST_F(PathTests, GetAbsolutePath_RelativePath_ReturnsCombinedPath) {
auto base = std::filesystem::path("/base");
auto relative = std::filesystem::path("relative/path");
EXPECT_EQ(GetAbsolutePath(base, relative), base / relative);
}

// Test cases for IsSubpath
TEST_F(PathTests, IsSubpath_Subpath_ReturnsTrue) {
auto base = std::filesystem::path("/base");
auto subpath = std::filesystem::path("/base/relative/path");
EXPECT_TRUE(IsSubpath(base, subpath));
}

TEST_F(PathTests, IsSubpath_NotSubpath_ReturnsFalse) {
auto base = std::filesystem::path("/base");
auto notSubpath = std::filesystem::path("/other/path");
EXPECT_FALSE(IsSubpath(base, notSubpath));
}

TEST_F(PathTests, IsSubpath_EmptyRelative_ReturnsFalse) {
auto base = std::filesystem::path("/base");
auto emptyPath = std::filesystem::path("/base/");
EXPECT_FALSE(IsSubpath(base, emptyPath));
}

// Test cases for Subtract
TEST_F(PathTests, Subtract_SubtractingBaseFromSubPath_ReturnsRelativePath) {
auto base = std::filesystem::path("/base");
auto subPath = std::filesystem::path("/base/relative/path");
EXPECT_EQ(Subtract(subPath, base), std::filesystem::path("relative/path"));
}

TEST_F(PathTests, Subtract_NotASubPath_ReturnsOriginalPath) {
auto base = std::filesystem::path("/base");
auto notSubPath = std::filesystem::path("/other/path");
EXPECT_EQ(Subtract(notSubPath, base), notSubPath);
}

TEST_F(PathTests, Subtract_IdenticalPaths_ReturnsEmptyRelative) {
auto base = std::filesystem::path("/base");
EXPECT_EQ(Subtract(base, base), std::filesystem::path("."));
}
} // namespace file_manager_utils