feat: add RHI abstraction layer unit tests
- Add RHITestFixture with RHI_BACKEND env var support for backend selection - Add unit tests for: Device, Buffer, Texture, SwapChain, CommandList, CommandQueue, Shader, Fence, Sampler - Tests can run against D3D12 or OpenGL backends via RHI_BACKEND env var - Add integration folder placeholder for future integration tests
This commit is contained in:
47
tests/RHI/unit/fixtures/RHITestFixture.cpp
Normal file
47
tests/RHI/unit/fixtures/RHITestFixture.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "RHITestFixture.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
RHIType RHITestFixture::mBackendType = RHIType::D3D12;
|
||||
|
||||
void RHITestFixture::SetUpTestSuite() {
|
||||
}
|
||||
|
||||
void RHITestFixture::TearDownTestSuite() {
|
||||
}
|
||||
|
||||
void RHITestFixture::SetUp() {
|
||||
const char* backend = std::getenv("RHI_BACKEND");
|
||||
if (backend != nullptr) {
|
||||
std::string backendStr(backend);
|
||||
if (backendStr == "OpenGL" || backendStr == "opengl") {
|
||||
mBackendType = RHIType::OpenGL;
|
||||
} else if (backendStr == "D3D12" || backendStr == "d3d12") {
|
||||
mBackendType = RHIType::D3D12;
|
||||
}
|
||||
}
|
||||
|
||||
mDevice = RHIFactory::CreateRHIDevice(mBackendType);
|
||||
ASSERT_NE(mDevice, nullptr);
|
||||
|
||||
RHIDeviceDesc desc = {};
|
||||
desc.enableDebugLayer = true;
|
||||
desc.appName = L"RHIUnitTest";
|
||||
|
||||
bool initResult = mDevice->Initialize(desc);
|
||||
ASSERT_TRUE(initResult);
|
||||
}
|
||||
|
||||
void RHITestFixture::TearDown() {
|
||||
if (mDevice != nullptr) {
|
||||
mDevice->Shutdown();
|
||||
delete mDevice;
|
||||
mDevice = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user