Files
XCEngine/tests/Resources/test_resource_path.cpp

111 lines
2.9 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include <XCEngine/Resources/ResourcePath.h>
#include <XCEngine/Resources/ResourceTypes.h>
#include <XCEngine/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