Files
XCEngine/tests/Core/IO/test_resource_path.cpp
ssdfasd d575532966 docs: update TEST_SPEC.md and README.md to reflect new directory structure
- TEST_SPEC.md: Updated test directory structure to reflect Core/Asset,
  Core/IO, and Resources/<Type> subdirectories
- TEST_SPEC.md: Updated module names and test counts (852 total)
- TEST_SPEC.md: Updated build commands for new Resources subdirectories
- README.md: Updated engine structure with Core/Asset/ and Core/IO/
- README.md: Updated Resources section with layered architecture
- README.md: Updated test coverage table with accurate counts
2026-03-24 16:14:05 +08:00

111 lines
2.9 KiB
C++

#include <gtest/gtest.h>
#include <XCEngine/Core/IO/ResourcePath.h>
#include <XCEngine/Core/Asset/ResourceTypes.h>
#include <XCEngine/Core/Containers/String.h>
using namespace XCEngine::Resources;
using namespace XCEngine::Containers;
namespace {
TEST(ResourcePath, DefaultConstructor) {
ResourcePath path;
EXPECT_FALSE(path.IsValid());
}
TEST(ResourcePath, ConstructorWithCString) {
ResourcePath path("textures/player.png");
EXPECT_TRUE(path.IsValid());
EXPECT_EQ(path.GetPath(), "textures/player.png");
}
TEST(ResourcePath, ConstructorWithString) {
String str = "models/player.fbx";
ResourcePath path(str);
EXPECT_TRUE(path.IsValid());
EXPECT_EQ(path.GetPath(), str);
}
TEST(ResourcePath, GetExtension) {
ResourcePath path("textures/player.png");
EXPECT_EQ(path.GetExtension(), ".png");
}
TEST(ResourcePath, GetExtensionNoExtension) {
ResourcePath path("textures/player");
EXPECT_TRUE(path.GetExtension().Empty());
}
TEST(ResourcePath, GetStem) {
ResourcePath path("textures/player.png");
EXPECT_EQ(path.GetStem(), "player");
}
TEST(ResourcePath, GetStemNoExtension) {
ResourcePath path("textures/player");
EXPECT_EQ(path.GetStem(), "player");
}
TEST(ResourcePath, GetFileName) {
ResourcePath path("textures/player.png");
EXPECT_EQ(path.GetFileName(), "player.png");
}
TEST(ResourcePath, GetDirectory) {
ResourcePath path("textures/player.png");
EXPECT_EQ(path.GetDirectory(), "textures");
}
TEST(ResourcePath, GetDirectoryWithBackslash) {
ResourcePath path("textures\\player.png");
EXPECT_EQ(path.GetDirectory(), "textures");
}
TEST(ResourcePath, GetFullPath) {
ResourcePath path("textures/player.png");
EXPECT_EQ(path.GetFullPath(), "textures/player.png");
}
TEST(ResourcePath, HasExtension) {
ResourcePath path("textures/player.png");
EXPECT_TRUE(path.HasExtension(".png"));
EXPECT_FALSE(path.HasExtension(".jpg"));
}
TEST(ResourcePath, HasExtensionNoExtension) {
ResourcePath path("textures/player");
EXPECT_FALSE(path.HasExtension(".png"));
}
TEST(ResourcePath, HasAnyExtension) {
ResourcePath path("textures/player.png");
const char* extensions[] = { ".jpg", ".png", ".tga" };
EXPECT_TRUE(path.HasAnyExtension(extensions, 3));
}
TEST(ResourcePath, HasAnyExtensionNoMatch) {
ResourcePath path("textures/player.png");
const char* extensions[] = { ".jpg", ".tga", ".bmp" };
EXPECT_FALSE(path.HasAnyExtension(extensions, 3));
}
TEST(ResourcePath, ToGUID) {
ResourcePath path("textures/player.png");
ResourceGUID guid = path.ToGUID();
EXPECT_TRUE(guid.IsValid());
}
TEST(ResourcePath, SetPath) {
ResourcePath path;
path.SetPath("textures/player.png");
EXPECT_TRUE(path.IsValid());
EXPECT_EQ(path.GetPath(), "textures/player.png");
}
TEST(ResourcePath, GetRelativePath) {
ResourcePath path("textures/player.png");
EXPECT_EQ(path.GetRelativePath(), "textures/player.png");
}
} // namespace