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>
|
2026-04-02 19:00:48 +08:00
|
|
|
#include <XCEngine/Resources/BuiltinResources.h>
|
|
|
|
|
#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/Resources/Shader/ShaderLoader.h>
|
|
|
|
|
#include <XCEngine/Core/Asset/ResourceTypes.h>
|
|
|
|
|
#include <XCEngine/Core/Containers/Array.h>
|
|
|
|
|
|
2026-04-02 16:10:50 +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(ShaderLoader, GetResourceType) {
|
|
|
|
|
ShaderLoader loader;
|
|
|
|
|
EXPECT_EQ(loader.GetResourceType(), ResourceType::Shader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ShaderLoader, GetSupportedExtensions) {
|
|
|
|
|
ShaderLoader loader;
|
|
|
|
|
auto extensions = loader.GetSupportedExtensions();
|
|
|
|
|
EXPECT_GE(extensions.Size(), 1u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ShaderLoader, CanLoad) {
|
|
|
|
|
ShaderLoader loader;
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.vert"));
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.frag"));
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.glsl"));
|
|
|
|
|
EXPECT_TRUE(loader.CanLoad("test.hlsl"));
|
2026-04-02 19:00:48 +08:00
|
|
|
EXPECT_TRUE(loader.CanLoad(GetBuiltinForwardLitShaderPath()));
|
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(ShaderLoader, LoadInvalidPath) {
|
|
|
|
|
ShaderLoader loader;
|
|
|
|
|
LoadResult result = loader.Load("invalid/path/shader.glsl");
|
|
|
|
|
EXPECT_FALSE(result);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 16:10:50 +08:00
|
|
|
TEST(ShaderLoader, LoadLegacySingleStageShaderBuildsDefaultPassVariant) {
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
|
|
const fs::path shaderPath = fs::temp_directory_path() / "xc_shader_loader_stage.vert";
|
|
|
|
|
{
|
|
|
|
|
std::ofstream shaderFile(shaderPath);
|
|
|
|
|
ASSERT_TRUE(shaderFile.is_open());
|
|
|
|
|
shaderFile << "#version 430\nvoid main() {}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShaderLoader loader;
|
|
|
|
|
LoadResult result = loader.Load(shaderPath.string().c_str());
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
ASSERT_NE(result.resource, nullptr);
|
|
|
|
|
|
|
|
|
|
Shader* shader = static_cast<Shader*>(result.resource);
|
|
|
|
|
ASSERT_NE(shader, nullptr);
|
|
|
|
|
EXPECT_EQ(shader->GetShaderType(), ShaderType::Vertex);
|
|
|
|
|
ASSERT_EQ(shader->GetPassCount(), 1u);
|
|
|
|
|
|
|
|
|
|
const ShaderPass* pass = shader->FindPass("Default");
|
|
|
|
|
ASSERT_NE(pass, nullptr);
|
|
|
|
|
ASSERT_EQ(pass->variants.Size(), 1u);
|
|
|
|
|
EXPECT_EQ(pass->variants[0].stage, ShaderType::Vertex);
|
|
|
|
|
EXPECT_EQ(pass->variants[0].backend, ShaderBackend::Generic);
|
|
|
|
|
EXPECT_EQ(pass->variants[0].sourceCode, shader->GetSourceCode());
|
|
|
|
|
|
|
|
|
|
delete shader;
|
|
|
|
|
std::remove(shaderPath.string().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 19:00:48 +08:00
|
|
|
TEST(ShaderLoader, LoadBuiltinForwardLitShaderBuildsBackendVariants) {
|
|
|
|
|
ShaderLoader loader;
|
|
|
|
|
LoadResult result = loader.Load(GetBuiltinForwardLitShaderPath());
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
ASSERT_NE(result.resource, nullptr);
|
|
|
|
|
|
|
|
|
|
Shader* shader = static_cast<Shader*>(result.resource);
|
|
|
|
|
ASSERT_NE(shader, nullptr);
|
|
|
|
|
ASSERT_TRUE(shader->IsValid());
|
|
|
|
|
|
|
|
|
|
const ShaderPass* pass = shader->FindPass("ForwardLit");
|
|
|
|
|
ASSERT_NE(pass, nullptr);
|
|
|
|
|
ASSERT_EQ(pass->variants.Size(), 6u);
|
|
|
|
|
ASSERT_EQ(pass->tags.Size(), 1u);
|
|
|
|
|
EXPECT_EQ(pass->tags[0].name, "LightMode");
|
|
|
|
|
EXPECT_EQ(pass->tags[0].value, "ForwardBase");
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(shader->FindVariant("ForwardLit", ShaderType::Vertex, ShaderBackend::D3D12), nullptr);
|
|
|
|
|
EXPECT_NE(shader->FindVariant("ForwardLit", ShaderType::Fragment, ShaderBackend::D3D12), nullptr);
|
|
|
|
|
EXPECT_NE(shader->FindVariant("ForwardLit", ShaderType::Vertex, ShaderBackend::OpenGL), nullptr);
|
|
|
|
|
EXPECT_NE(shader->FindVariant("ForwardLit", ShaderType::Fragment, ShaderBackend::OpenGL), nullptr);
|
|
|
|
|
EXPECT_NE(shader->FindVariant("ForwardLit", ShaderType::Vertex, ShaderBackend::Vulkan), nullptr);
|
|
|
|
|
EXPECT_NE(shader->FindVariant("ForwardLit", ShaderType::Fragment, ShaderBackend::Vulkan), nullptr);
|
|
|
|
|
|
|
|
|
|
delete shader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ShaderLoader, ResourceManagerLazilyLoadsBuiltinForwardLitShader) {
|
|
|
|
|
ResourceManager& manager = ResourceManager::Get();
|
|
|
|
|
manager.Shutdown();
|
|
|
|
|
manager.UnregisterLoader(ResourceType::Shader);
|
|
|
|
|
|
|
|
|
|
ResourceHandle<Shader> shaderHandle = manager.Load<Shader>(GetBuiltinForwardLitShaderPath());
|
|
|
|
|
ASSERT_TRUE(shaderHandle.IsValid());
|
|
|
|
|
ASSERT_NE(shaderHandle->FindPass("ForwardLit"), nullptr);
|
|
|
|
|
|
|
|
|
|
manager.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
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
|