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/Material/MaterialLoader.h>
|
2026-03-27 00:30:49 +08:00
|
|
|
#include <XCEngine/Core/Asset/ResourceManager.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-27 00:30:49 +08:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
TEST(MaterialLoader, GetResourceType) {
|
|
|
|
|
MaterialLoader loader;
|
|
|
|
|
EXPECT_EQ(loader.GetResourceType(), ResourceType::Material);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MaterialLoader, GetSupportedExtensions) {
|
|
|
|
|
MaterialLoader loader;
|
|
|
|
|
auto extensions = loader.GetSupportedExtensions();
|
|
|
|
|
EXPECT_GE(extensions.Size(), 1u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MaterialLoader, CanLoad) {
|
|
|
|
|
MaterialLoader loader;
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.mat"));
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.json"));
|
|
|
|
|
EXPECT_FALSE(loader.CanLoad("test.txt"));
|
|
|
|
|
EXPECT_FALSE(loader.CanLoad("test.png"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MaterialLoader, LoadInvalidPath) {
|
|
|
|
|
MaterialLoader loader;
|
|
|
|
|
LoadResult result = loader.Load("invalid/path/material.mat");
|
|
|
|
|
EXPECT_FALSE(result);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 00:30:49 +08:00
|
|
|
TEST(MaterialLoader, ResourceManagerRegistersMaterialAndShaderLoaders) {
|
|
|
|
|
ResourceManager& manager = ResourceManager::Get();
|
|
|
|
|
manager.Initialize();
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(manager.GetLoader(ResourceType::Material), nullptr);
|
|
|
|
|
EXPECT_NE(manager.GetLoader(ResourceType::Shader), nullptr);
|
|
|
|
|
|
|
|
|
|
manager.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MaterialLoader, LoadValidMaterialParsesRenderMetadata) {
|
|
|
|
|
const std::filesystem::path shaderPath =
|
|
|
|
|
std::filesystem::current_path() / "material_loader_valid_shader.hlsl";
|
|
|
|
|
const std::filesystem::path materialPath =
|
|
|
|
|
std::filesystem::current_path() / "material_loader_valid.material";
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::ofstream shaderFile(shaderPath);
|
|
|
|
|
ASSERT_TRUE(shaderFile.is_open());
|
|
|
|
|
shaderFile << "float4 MainPS() : SV_TARGET { return float4(1, 1, 1, 1); }";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::ofstream materialFile(materialPath);
|
|
|
|
|
ASSERT_TRUE(materialFile.is_open());
|
|
|
|
|
materialFile << "{\n";
|
|
|
|
|
materialFile << " \"shader\": \"" << shaderPath.generic_string() << "\",\n";
|
|
|
|
|
materialFile << " \"renderQueue\": \"Transparent\",\n";
|
|
|
|
|
materialFile << " \"shaderPass\": \"ForwardLit\",\n";
|
|
|
|
|
materialFile << " \"tags\": {\n";
|
|
|
|
|
materialFile << " \"LightMode\": \"ForwardBase\",\n";
|
|
|
|
|
materialFile << " \"RenderType\": \"Transparent\"\n";
|
|
|
|
|
materialFile << " }\n";
|
|
|
|
|
materialFile << "}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaterialLoader loader;
|
|
|
|
|
LoadResult result = loader.Load(materialPath.string().c_str());
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
ASSERT_NE(result.resource, nullptr);
|
|
|
|
|
|
|
|
|
|
Material* material = static_cast<Material*>(result.resource);
|
|
|
|
|
ASSERT_NE(material, nullptr);
|
|
|
|
|
EXPECT_TRUE(material->IsValid());
|
|
|
|
|
EXPECT_NE(material->GetShader(), nullptr);
|
|
|
|
|
EXPECT_EQ(material->GetRenderQueue(), static_cast<XCEngine::Core::int32>(MaterialRenderQueue::Transparent));
|
|
|
|
|
EXPECT_EQ(material->GetShaderPass(), "ForwardLit");
|
|
|
|
|
EXPECT_EQ(material->GetTag("LightMode"), "ForwardBase");
|
|
|
|
|
EXPECT_EQ(material->GetTag("RenderType"), "Transparent");
|
|
|
|
|
|
|
|
|
|
delete material;
|
|
|
|
|
std::remove(materialPath.string().c_str());
|
|
|
|
|
std::remove(shaderPath.string().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MaterialLoader, RejectsUnknownRenderQueueName) {
|
|
|
|
|
const std::filesystem::path materialPath =
|
|
|
|
|
std::filesystem::current_path() / "material_loader_invalid_queue.material";
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::ofstream materialFile(materialPath);
|
|
|
|
|
ASSERT_TRUE(materialFile.is_open());
|
|
|
|
|
materialFile << "{ \"renderQueue\": \"NotAQueue\" }";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaterialLoader loader;
|
|
|
|
|
LoadResult result = loader.Load(materialPath.string().c_str());
|
|
|
|
|
EXPECT_FALSE(result);
|
|
|
|
|
|
|
|
|
|
std::remove(materialPath.string().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
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
|