Files
XCEngine/tests/RHI/OpenGL/fixtures/OpenGLTestFixture.h
ssdfasd 745f3ab225 Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00

54 lines
1.2 KiB
C++

#pragma once
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <gtest/gtest.h>
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
namespace XCEngine {
namespace RHI {
class OpenGLTestFixture : public ::testing::Test {
protected:
static void SetUpTestSuite();
static void TearDownTestSuite();
void SetUp() override;
void TearDown() override;
GLFWwindow* GetWindow() { return m_window; }
void MakeContextCurrent();
void DoneContextCurrent();
void ClearGLErrors();
bool CheckGLError(const char* file, int line);
const char* GetGLErrorString(GLenum error);
void ResetGLState();
private:
static GLFWwindow* m_window;
static bool m_contextInitialized;
static OpenGLDevice* m_device;
};
} // namespace RHI
} // namespace XCEngine
#define GL_CLEAR_ERRORS() \
do { while (glGetError() != GL_NO_ERROR); } while(0)
#define GL_CHECK(call) \
do { \
call; \
ASSERT_TRUE(XCEngine::RHI::OpenGLTestFixture::CheckGLError(__FILE__, __LINE__)) \
<< "GL error after " << #call; \
} while(0)
#define GL_EXPECT_SUCCESS(call) \
do { \
call; \
EXPECT_EQ(glGetError(), GL_NO_ERROR) \
<< "GL error after " << #call; \
} while(0)