refactor(tests): reorganize tests directory to match engine structure
- Created tests/Core/Asset/ with tests for IResource, ResourceTypes, ResourceHandle, ResourceCache, ResourceDependencyGraph, ResourceGUID
- Created tests/Core/IO/ with tests for IResourceLoader, ResourcePath, ResourceFileSystem, FileArchive, ResourcePackage
- Reorganized tests/Resources/ into subdirectories: Texture/, Mesh/, Material/, Shader/, AudioClip/
- Added CMakeLists.txt for each new test subdirectory
- Fixed Material.h missing ResourceManager.h include (lost during engine refactor)
- tests/Core/CMakeLists.txt updated to include Asset/ and IO/ subdirectories
2026-03-24 15:44:13 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <XCEngine/Resources/Mesh/MeshLoader.h>
|
2026-03-26 02:53:34 +08:00
|
|
|
#include <XCEngine/Resources/Mesh/MeshImportSettings.h>
|
refactor(tests): reorganize tests directory to match engine structure
- Created tests/Core/Asset/ with tests for IResource, ResourceTypes, ResourceHandle, ResourceCache, ResourceDependencyGraph, ResourceGUID
- Created tests/Core/IO/ with tests for IResourceLoader, ResourcePath, ResourceFileSystem, FileArchive, ResourcePackage
- Reorganized tests/Resources/ into subdirectories: Texture/, Mesh/, Material/, Shader/, AudioClip/
- Added CMakeLists.txt for each new test subdirectory
- Fixed Material.h missing ResourceManager.h include (lost during engine refactor)
- tests/Core/CMakeLists.txt updated to include Asset/ and IO/ subdirectories
2026-03-24 15:44:13 +08:00
|
|
|
#include <XCEngine/Core/Asset/ResourceTypes.h>
|
|
|
|
|
#include <XCEngine/Core/Containers/Array.h>
|
2026-03-26 02:53:34 +08:00
|
|
|
#include <filesystem>
|
refactor(tests): reorganize tests directory to match engine structure
- Created tests/Core/Asset/ with tests for IResource, ResourceTypes, ResourceHandle, ResourceCache, ResourceDependencyGraph, ResourceGUID
- Created tests/Core/IO/ with tests for IResourceLoader, ResourcePath, ResourceFileSystem, FileArchive, ResourcePackage
- Reorganized tests/Resources/ into subdirectories: Texture/, Mesh/, Material/, Shader/, AudioClip/
- Added CMakeLists.txt for each new test subdirectory
- Fixed Material.h missing ResourceManager.h include (lost during engine refactor)
- tests/Core/CMakeLists.txt updated to include Asset/ and IO/ subdirectories
2026-03-24 15:44:13 +08:00
|
|
|
|
|
|
|
|
using namespace XCEngine::Resources;
|
|
|
|
|
using namespace XCEngine::Containers;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2026-03-26 02:53:34 +08:00
|
|
|
std::string GetMeshFixturePath(const char* fileName) {
|
|
|
|
|
return (std::filesystem::path(XCENGINE_TEST_FIXTURES_DIR) / "Resources" / "Mesh" / fileName).string();
|
|
|
|
|
}
|
|
|
|
|
|
refactor(tests): reorganize tests directory to match engine structure
- Created tests/Core/Asset/ with tests for IResource, ResourceTypes, ResourceHandle, ResourceCache, ResourceDependencyGraph, ResourceGUID
- Created tests/Core/IO/ with tests for IResourceLoader, ResourcePath, ResourceFileSystem, FileArchive, ResourcePackage
- Reorganized tests/Resources/ into subdirectories: Texture/, Mesh/, Material/, Shader/, AudioClip/
- Added CMakeLists.txt for each new test subdirectory
- Fixed Material.h missing ResourceManager.h include (lost during engine refactor)
- tests/Core/CMakeLists.txt updated to include Asset/ and IO/ subdirectories
2026-03-24 15:44:13 +08:00
|
|
|
TEST(MeshLoader, GetResourceType) {
|
|
|
|
|
MeshLoader loader;
|
|
|
|
|
EXPECT_EQ(loader.GetResourceType(), ResourceType::Mesh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MeshLoader, GetSupportedExtensions) {
|
|
|
|
|
MeshLoader loader;
|
|
|
|
|
auto extensions = loader.GetSupportedExtensions();
|
|
|
|
|
EXPECT_GE(extensions.Size(), 1u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MeshLoader, CanLoad) {
|
|
|
|
|
MeshLoader loader;
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.obj"));
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.fbx"));
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.gltf"));
|
2026-03-26 02:53:34 +08:00
|
|
|
EXPECT_TRUE(loader.CanLoad("test.OBJ"));
|
refactor(tests): reorganize tests directory to match engine structure
- Created tests/Core/Asset/ with tests for IResource, ResourceTypes, ResourceHandle, ResourceCache, ResourceDependencyGraph, ResourceGUID
- Created tests/Core/IO/ with tests for IResourceLoader, ResourcePath, ResourceFileSystem, FileArchive, ResourcePackage
- Reorganized tests/Resources/ into subdirectories: Texture/, Mesh/, Material/, Shader/, AudioClip/
- Added CMakeLists.txt for each new test subdirectory
- Fixed Material.h missing ResourceManager.h include (lost during engine refactor)
- tests/Core/CMakeLists.txt updated to include Asset/ and IO/ subdirectories
2026-03-24 15:44:13 +08:00
|
|
|
EXPECT_FALSE(loader.CanLoad("test.txt"));
|
|
|
|
|
EXPECT_FALSE(loader.CanLoad("test.png"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MeshLoader, LoadInvalidPath) {
|
|
|
|
|
MeshLoader loader;
|
|
|
|
|
LoadResult result = loader.Load("invalid/path/mesh.obj");
|
|
|
|
|
EXPECT_FALSE(result);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 02:53:34 +08:00
|
|
|
TEST(MeshLoader, LoadValidObjMesh) {
|
|
|
|
|
MeshLoader loader;
|
|
|
|
|
const std::string path = GetMeshFixturePath("triangle.obj");
|
|
|
|
|
|
|
|
|
|
LoadResult result = loader.Load(path.c_str());
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
ASSERT_NE(result.resource, nullptr);
|
|
|
|
|
|
|
|
|
|
auto* mesh = static_cast<Mesh*>(result.resource);
|
|
|
|
|
EXPECT_EQ(mesh->GetVertexCount(), 3u);
|
|
|
|
|
EXPECT_EQ(mesh->GetIndexCount(), 3u);
|
|
|
|
|
EXPECT_EQ(mesh->GetVertexStride(), sizeof(StaticMeshVertex));
|
|
|
|
|
EXPECT_FALSE(mesh->IsUse32BitIndex());
|
|
|
|
|
ASSERT_EQ(mesh->GetSections().Size(), 1u);
|
|
|
|
|
EXPECT_EQ(mesh->GetSections()[0].vertexCount, 3u);
|
|
|
|
|
EXPECT_EQ(mesh->GetSections()[0].indexCount, 3u);
|
|
|
|
|
EXPECT_TRUE(HasVertexAttribute(mesh->GetVertexAttributes(), VertexAttribute::Position));
|
|
|
|
|
EXPECT_TRUE(HasVertexAttribute(mesh->GetVertexAttributes(), VertexAttribute::Normal));
|
|
|
|
|
EXPECT_TRUE(HasVertexAttribute(mesh->GetVertexAttributes(), VertexAttribute::UV0));
|
|
|
|
|
|
|
|
|
|
const auto* vertices = static_cast<const StaticMeshVertex*>(mesh->GetVertexData());
|
|
|
|
|
ASSERT_NE(vertices, nullptr);
|
|
|
|
|
EXPECT_FLOAT_EQ(vertices[0].position.x, 0.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(vertices[0].position.y, 0.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(vertices[0].position.z, -1.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(vertices[0].normal.z, -1.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(vertices[1].uv0.x, 1.0f);
|
|
|
|
|
EXPECT_FLOAT_EQ(vertices[2].uv0.y, 1.0f);
|
|
|
|
|
|
|
|
|
|
delete mesh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MeshLoader, GeneratesNormalsAndTangentsWhenRequested) {
|
|
|
|
|
MeshLoader loader;
|
|
|
|
|
MeshImportSettings settings;
|
|
|
|
|
settings.AddImportFlag(MeshImportFlags::GenerateNormals);
|
|
|
|
|
settings.AddImportFlag(MeshImportFlags::GenerateTangents);
|
|
|
|
|
|
|
|
|
|
const std::string path = GetMeshFixturePath("triangle_no_normals.obj");
|
|
|
|
|
LoadResult result = loader.Load(path.c_str(), &settings);
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
ASSERT_NE(result.resource, nullptr);
|
|
|
|
|
|
|
|
|
|
auto* mesh = static_cast<Mesh*>(result.resource);
|
|
|
|
|
EXPECT_TRUE(HasVertexAttribute(mesh->GetVertexAttributes(), VertexAttribute::Normal));
|
|
|
|
|
EXPECT_TRUE(HasVertexAttribute(mesh->GetVertexAttributes(), VertexAttribute::Tangent));
|
|
|
|
|
EXPECT_TRUE(HasVertexAttribute(mesh->GetVertexAttributes(), VertexAttribute::Bitangent));
|
|
|
|
|
|
|
|
|
|
const auto* vertices = static_cast<const StaticMeshVertex*>(mesh->GetVertexData());
|
|
|
|
|
ASSERT_NE(vertices, nullptr);
|
|
|
|
|
EXPECT_GT(vertices[0].normal.Magnitude(), 0.0f);
|
|
|
|
|
EXPECT_GT(vertices[0].tangent.Magnitude(), 0.0f);
|
|
|
|
|
EXPECT_GT(vertices[0].bitangent.Magnitude(), 0.0f);
|
|
|
|
|
|
|
|
|
|
delete mesh;
|
|
|
|
|
}
|
|
|
|
|
|
refactor(tests): reorganize tests directory to match engine structure
- Created tests/Core/Asset/ with tests for IResource, ResourceTypes, ResourceHandle, ResourceCache, ResourceDependencyGraph, ResourceGUID
- Created tests/Core/IO/ with tests for IResourceLoader, ResourcePath, ResourceFileSystem, FileArchive, ResourcePackage
- Reorganized tests/Resources/ into subdirectories: Texture/, Mesh/, Material/, Shader/, AudioClip/
- Added CMakeLists.txt for each new test subdirectory
- Fixed Material.h missing ResourceManager.h include (lost during engine refactor)
- tests/Core/CMakeLists.txt updated to include Asset/ and IO/ subdirectories
2026-03-24 15:44:13 +08:00
|
|
|
} // namespace
|