From a44f05d9e51487e24789a6bf96e3147567fdb3db Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Wed, 7 Jan 2026 23:16:58 +0000 Subject: [PATCH] feat(tests): add shader pipeline validator tests with GTest integration --- CMakeLists.txt | 13 ++++++ tests/shader_pipeline_validator_test.cpp | 59 +++++++++++++++++------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index beec157..e8ad5dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,7 @@ find_package(Vorbis CONFIG REQUIRED) find_package(glm CONFIG REQUIRED) find_package(cpptrace REQUIRED) find_package(stb CONFIG REQUIRED) +find_package(GTest CONFIG REQUIRED) set(SDL3CPP_RENDER_STACK_LIBS EnTT::EnTT) if(TARGET bgfx::bgfx) @@ -490,6 +491,18 @@ else() message(WARNING "shaderc CMake target not found; skipping link for vulkan_shader_linking_test.") endif() add_test(NAME vulkan_shader_linking_test COMMAND vulkan_shader_linking_test) + +# Test: Shader Pipeline Validator (mega-strict validation system) +add_executable(shader_pipeline_validator_test + tests/shader_pipeline_validator_test.cpp + src/services/impl/shader_pipeline_validator.cpp +) +target_include_directories(shader_pipeline_validator_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") +target_link_libraries(shader_pipeline_validator_test PRIVATE + GTest::gtest + GTest::gtest_main +) +add_test(NAME shader_pipeline_validator_test COMMAND shader_pipeline_validator_test) endif() if(ENABLE_VITA) diff --git a/tests/shader_pipeline_validator_test.cpp b/tests/shader_pipeline_validator_test.cpp index eba498e..f993e90 100644 --- a/tests/shader_pipeline_validator_test.cpp +++ b/tests/shader_pipeline_validator_test.cpp @@ -1,7 +1,7 @@ #include "services/impl/shader_pipeline_validator.hpp" +#include "services/interfaces/i_logger.hpp" #include "core/vertex.hpp" -#include -#include +#include #include using namespace sdl3cpp::services; @@ -9,29 +9,56 @@ using namespace sdl3cpp::services; // Mock logger for testing class MockLogger : public ILogger { public: + void SetLevel(LogLevel) override {} + LogLevel GetLevel() const override { return LogLevel::INFO; } + void SetOutputFile(const std::string&) override {} + void SetMaxLinesPerFile(size_t) override {} + void EnableConsoleOutput(bool) override {} + void Log(LogLevel, const std::string&) override {} + void Trace(const std::string&) override {} + void Trace(const std::string&, const std::string&, const std::string&, const std::string&) override {} void Debug(const std::string&) override {} void Info(const std::string&) override {} void Warn(const std::string&) override {} void Error(const std::string&) override {} - void Trace(const std::string&) override {} + void TraceFunction(const std::string&) override {} + void TraceVariable(const std::string&, const std::string&) override {} + void TraceVariable(const std::string&, int) override {} + void TraceVariable(const std::string&, size_t) override {} + void TraceVariable(const std::string&, bool) override {} + void TraceVariable(const std::string&, float) override {} + void TraceVariable(const std::string&, double) override {} }; -int TestExtractShaderInputs() { - std::cout << "TEST: ExtractShaderInputs\n"; - int failures = 0; +class ShaderPipelineValidatorTest : public ::testing::Test { +protected: + void SetUp() override { + logger = std::make_shared(); + validator = std::make_unique(logger); + } - auto logger = std::make_shared(); - ShaderPipelineValidator validator(logger); + std::shared_ptr logger; + std::unique_ptr validator; +}; - std::string validGlsl = R"( - #version 450 - layout (location = 0) in vec3 i_position; - layout (location = 1) in vec3 i_normal; - layout (location = 2) in vec2 i_texcoord_0; - void main() {} - )"; +// ============================================================================ +// Test: Extract Shader Inputs +// ============================================================================ - auto inputs = validator.ExtractShaderInputs(validGlsl); +TEST_F(ShaderPipelineValidatorTest, ExtractShaderInputs_ValidGLSL) { + std::string glsl = R"( +#version 450 +layout (location = 0) in vec3 i_position; +layout (location = 1) in vec3 i_normal; +layout (location = 2) in vec3 i_tangent; +layout (location = 3) in vec2 i_texcoord_0; + +void main() { + gl_Position = vec4(i_position, 1.0); +} +)"; + + auto inputs = validator->ExtractShaderInputs(glsl); ASSERT_EQ(inputs.size(), 4);