mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat(tests): add shader pipeline validator tests with GTest integration
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "services/impl/shader_pipeline_validator.hpp"
|
||||
#include "services/interfaces/i_logger.hpp"
|
||||
#include "core/vertex.hpp"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
|
||||
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<MockLogger>();
|
||||
validator = std::make_unique<ShaderPipelineValidator>(logger);
|
||||
}
|
||||
|
||||
auto logger = std::make_shared<MockLogger>();
|
||||
ShaderPipelineValidator validator(logger);
|
||||
std::shared_ptr<MockLogger> logger;
|
||||
std::unique_ptr<ShaderPipelineValidator> 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user