mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
Import SDL3CPlusPlus C++ game engine with: - SDL3 + bgfx rendering backend - Vulkan/Metal/DirectX shader support - MaterialX material system - Scene framework with ECS architecture - Comprehensive test suite (TDD approach) - Conan package management - CMake build system This provides the native C++ foundation for the Universal Platform's Game and 3D capability modules. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
233 lines
5.9 KiB
C++
233 lines
5.9 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "services/impl/config/config_compiler_service.hpp"
|
|
|
|
namespace {
|
|
|
|
bool HasDiagnosticCode(const std::vector<sdl3cpp::services::ProbeReport>& diagnostics,
|
|
const std::string& code) {
|
|
for (const auto& report : diagnostics) {
|
|
if (report.code == code) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsUnknownShaderReference) {
|
|
const std::string json = R"({
|
|
"assets": {
|
|
"shaders": {
|
|
"known": { "vs": "shaders/known.vs", "fs": "shaders/known.fs" }
|
|
}
|
|
},
|
|
"materials": {
|
|
"mat": {
|
|
"shader": "missing"
|
|
}
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "MATERIAL_SHADER_UNKNOWN"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsUnknownTextureReference) {
|
|
const std::string json = R"({
|
|
"assets": {
|
|
"textures": {
|
|
"tex1": { "uri": "textures/tex1.png" }
|
|
},
|
|
"shaders": {
|
|
"known": { "vs": "shaders/known.vs", "fs": "shaders/known.fs" }
|
|
}
|
|
},
|
|
"materials": {
|
|
"mat": {
|
|
"shader": "known",
|
|
"textures": {
|
|
"u_albedo": "missing"
|
|
}
|
|
}
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "MATERIAL_TEXTURE_UNKNOWN"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsUnknownPassOutput) {
|
|
const std::string json = R"({
|
|
"render": {
|
|
"passes": [
|
|
{
|
|
"id": "first",
|
|
"outputs": {
|
|
"color": { "format": "RGBA8", "usage": "renderTarget" }
|
|
}
|
|
},
|
|
{
|
|
"id": "second",
|
|
"inputs": {
|
|
"source": "@pass.first.missing"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "RG_INPUT_UNKNOWN_OUTPUT"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsUnknownPassReference) {
|
|
const std::string json = R"({
|
|
"render": {
|
|
"passes": [
|
|
{
|
|
"id": "second",
|
|
"inputs": {
|
|
"source": "@pass.missing.color"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "RG_INPUT_UNKNOWN_PASS"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsSelfReference) {
|
|
const std::string json = R"({
|
|
"render": {
|
|
"passes": [
|
|
{
|
|
"id": "self",
|
|
"inputs": {
|
|
"source": "@pass.self.color"
|
|
},
|
|
"outputs": {
|
|
"color": { "format": "RGBA8", "usage": "renderTarget" }
|
|
}
|
|
}
|
|
]
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "RG_INPUT_SELF_REFERENCE"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsInvalidViewId) {
|
|
const std::string json = R"({
|
|
"render": {
|
|
"passes": [
|
|
{
|
|
"id": "main",
|
|
"view_id": "bad"
|
|
}
|
|
]
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "RG_VIEW_ID_TYPE"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsInvalidClearColor) {
|
|
const std::string json = R"({
|
|
"render": {
|
|
"passes": [
|
|
{
|
|
"id": "main",
|
|
"clear": {
|
|
"flags": ["color"],
|
|
"color": [1.0, 0.5, 0.25]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "RG_CLEAR_COLOR"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsInvalidShaderSystemType) {
|
|
const std::string json = R"({
|
|
"assets": {
|
|
"shaders": {
|
|
"pbr": { "vs": "shaders/pbr.vs", "fs": "shaders/pbr.fs", "system": 3 }
|
|
}
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "ASSET_SHADER_SYSTEM_TYPE"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsUnknownShaderSystem) {
|
|
const std::string json = R"({
|
|
"shader_systems": {
|
|
"systems": {
|
|
"glsl": { "enabled": true }
|
|
}
|
|
},
|
|
"assets": {
|
|
"shaders": {
|
|
"pbr": { "vs": "shaders/pbr.vs", "fs": "shaders/pbr.fs", "system": "materialx" }
|
|
}
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "ASSET_SHADER_SYSTEM_UNKNOWN"));
|
|
}
|
|
|
|
TEST(ConfigCompilerReferenceValidationTest, FlagsUnknownActiveShaderSystem) {
|
|
const std::string json = R"({
|
|
"shader_systems": {
|
|
"active": "missing",
|
|
"systems": {
|
|
"glsl": { "enabled": true }
|
|
}
|
|
}
|
|
})";
|
|
|
|
sdl3cpp::services::impl::ConfigCompilerService compiler(nullptr, nullptr, nullptr, nullptr);
|
|
auto result = compiler.Compile(json);
|
|
|
|
EXPECT_FALSE(result.success);
|
|
EXPECT_TRUE(HasDiagnosticCode(result.diagnostics, "SHADER_SYSTEMS_ACTIVE_UNKNOWN"));
|
|
}
|
|
|
|
} // namespace
|