Files
XCEngine/tests/RHI/unit/test_swap_chain.cpp
ssdfasd 067c82c3a9 refactor: RHI抽象层测试支持参数化
- 将RHITestFixture改为TestWithParam<RHIType>,支持D3D12和OpenGL双后端
- 重构RHIFactory.cpp的include结构,修复OpenGL设备创建
- 在CMakeLists.txt中添加XCENGINE_SUPPORT_OPENGL宏定义
- 更新engine/CMakeLists.txt和tests/RHI/unit/CMakeLists.txt
- 将所有TEST_F改为TEST_P以支持参数化测试

测试结果: 138 tests (D3D12: 58 passed / OpenGL: 48 passed)
2026-03-23 19:17:32 +08:00

111 lines
2.9 KiB
C++

#include "fixtures/RHITestFixture.h"
#include "XCEngine/RHI/RHISwapChain.h"
using namespace XCEngine::RHI;
TEST_P(RHITestFixture, SwapChain_Create) {
SwapChainDesc desc = {};
desc.width = 800;
desc.height = 600;
desc.bufferCount = 2;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.refreshRate = 60;
desc.sampleCount = 1;
desc.sampleQuality = 0;
desc.swapEffect = 0;
desc.flags = 0;
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
ASSERT_NE(swapChain, nullptr);
swapChain->Shutdown();
delete swapChain;
}
TEST_P(RHITestFixture, SwapChain_GetCurrentBackBufferIndex) {
SwapChainDesc desc = {};
desc.width = 800;
desc.height = 600;
desc.bufferCount = 2;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
ASSERT_NE(swapChain, nullptr);
uint32_t index = swapChain->GetCurrentBackBufferIndex();
EXPECT_LT(index, 2u);
swapChain->Shutdown();
delete swapChain;
}
TEST_P(RHITestFixture, SwapChain_GetCurrentBackBuffer) {
SwapChainDesc desc = {};
desc.width = 800;
desc.height = 600;
desc.bufferCount = 2;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
ASSERT_NE(swapChain, nullptr);
RHITexture* backBuffer = swapChain->GetCurrentBackBuffer();
EXPECT_NE(backBuffer, nullptr);
swapChain->Shutdown();
delete swapChain;
}
TEST_P(RHITestFixture, SwapChain_Resize) {
SwapChainDesc desc = {};
desc.width = 800;
desc.height = 600;
desc.bufferCount = 2;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
ASSERT_NE(swapChain, nullptr);
swapChain->Resize(1024, 768);
swapChain->Shutdown();
delete swapChain;
}
TEST_P(RHITestFixture, SwapChain_FullscreenState) {
SwapChainDesc desc = {};
desc.width = 800;
desc.height = 600;
desc.bufferCount = 2;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
ASSERT_NE(swapChain, nullptr);
EXPECT_FALSE(swapChain->IsFullscreen());
swapChain->SetFullscreen(true);
EXPECT_TRUE(swapChain->IsFullscreen());
swapChain->SetFullscreen(false);
swapChain->Shutdown();
delete swapChain;
}
TEST_P(RHITestFixture, SwapChain_ShouldClose) {
SwapChainDesc desc = {};
desc.width = 800;
desc.height = 600;
desc.bufferCount = 2;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
ASSERT_NE(swapChain, nullptr);
EXPECT_FALSE(swapChain->ShouldClose());
swapChain->SetShouldClose(true);
EXPECT_TRUE(swapChain->ShouldClose());
swapChain->Shutdown();
delete swapChain;
}