Files
XCEngine/tests/RHI/unit/test_device.cpp
ssdfasd 0fa4f2e3a8 Fix RHI unit test failures and OpenGL backend issues
- Fix D3D12Texture::GetTextureType() to return correct type based on D3D12 resource dimension
- Fix OpenGL CommandQueue::Signal() to properly call fence->Signal()
- Fix OpenGL CommandQueue::GetTimestampFrequency() using GL_TIMESTAMP
- Fix OpenGL Device::GetNativeDevice() to return m_hglrc
- Fix OpenGL Fence::Signal() to create GL sync object and update completedValue
- Fix OpenGL Fence::Wait() to properly wait for fence
- Fix OpenGL Fence::GetNativeHandle() to create sync on first call
- Fix OpenGL SwapChain::GetCurrentBackBuffer() to return backbuffer texture
- Fix OpenGL SwapChain::Initialize() to create backbuffer texture
- Fix OpenGL SwapChain::Shutdown() to cleanup backbuffer texture
- Fix RHI unit tests: add missing sampleCount/sampleQuality/depth/arraySize fields
- Fix RHI unit tests: add complete TextureDesc fields where needed
2026-03-23 21:09:15 +08:00

128 lines
3.6 KiB
C++

#include "fixtures/RHITestFixture.h"
using namespace XCEngine::RHI;
TEST_P(RHITestFixture, Device_Create_Success) {
ASSERT_NE(GetDevice(), nullptr);
}
TEST_P(RHITestFixture, Device_Initialize_Shutdown) {
RHIDevice* device = RHIFactory::CreateRHIDevice(GetBackendType());
ASSERT_NE(device, nullptr);
RHIDeviceDesc desc = {};
desc.enableDebugLayer = true;
bool initResult = device->Initialize(desc);
ASSERT_TRUE(initResult);
device->Shutdown();
delete device;
}
TEST_P(RHITestFixture, Device_GetCapabilities_ReturnsValid) {
const auto& caps = GetDevice()->GetCapabilities();
EXPECT_GE(caps.maxTexture2DSize, 0u);
EXPECT_GE(caps.maxRenderTargets, 1u);
EXPECT_GE(caps.maxViewports, 1u);
EXPECT_GE(caps.maxVertexAttribs, 8u);
}
TEST_P(RHITestFixture, Device_GetDeviceInfo_ReturnsValid) {
const auto& info = GetDevice()->GetDeviceInfo();
EXPECT_FALSE(info.vendor.empty());
EXPECT_FALSE(info.renderer.empty());
}
TEST_P(RHITestFixture, Device_CreateBuffer_ReturnsValid) {
BufferDesc desc = {};
desc.size = 1024;
desc.stride = sizeof(float);
desc.bufferType = static_cast<uint32_t>(BufferType::Vertex);
RHIBuffer* buffer = GetDevice()->CreateBuffer(desc);
ASSERT_NE(buffer, nullptr);
EXPECT_EQ(buffer->GetSize(), 1024u);
buffer->Shutdown();
delete buffer;
}
TEST_P(RHITestFixture, Device_CreateTexture_ReturnsValid) {
TextureDesc desc = {};
desc.width = 512;
desc.height = 512;
desc.depth = 1;
desc.mipLevels = 1;
desc.arraySize = 1;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
desc.sampleCount = 1;
desc.sampleQuality = 0;
desc.flags = 0;
RHITexture* texture = GetDevice()->CreateTexture(desc);
ASSERT_NE(texture, nullptr);
EXPECT_EQ(texture->GetWidth(), 512u);
EXPECT_EQ(texture->GetHeight(), 512u);
texture->Shutdown();
delete texture;
}
TEST_P(RHITestFixture, Device_CreateFence_ReturnsValid) {
FenceDesc desc = {};
desc.initialValue = 0;
desc.flags = 0;
RHIFence* fence = GetDevice()->CreateFence(desc);
ASSERT_NE(fence, nullptr);
EXPECT_EQ(fence->GetCompletedValue(), 0u);
fence->Shutdown();
delete fence;
}
TEST_P(RHITestFixture, Device_CreateCommandQueue_ReturnsValid) {
CommandQueueDesc desc = {};
desc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(desc);
ASSERT_NE(queue, nullptr);
EXPECT_EQ(queue->GetType(), CommandQueueType::Direct);
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, Device_CreateCommandList_ReturnsValid) {
CommandListDesc desc = {};
desc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandList* cmdList = GetDevice()->CreateCommandList(desc);
ASSERT_NE(cmdList, nullptr);
cmdList->Shutdown();
delete cmdList;
}
TEST_P(RHITestFixture, Device_CreateSampler_ReturnsValid) {
SamplerDesc desc = {};
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Wrap);
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Wrap);
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Wrap);
RHISampler* sampler = GetDevice()->CreateSampler(desc);
ASSERT_NE(sampler, nullptr);
sampler->Shutdown();
delete sampler;
}
TEST_P(RHITestFixture, Device_GetNativeDevice_ReturnsValid) {
void* native = GetDevice()->GetNativeDevice();
ASSERT_NE(native, nullptr);
}