Files
XCEngine/tests/RHI/unit/test_device.cpp

162 lines
4.6 KiB
C++
Raw Normal View History

#include "fixtures/RHITestFixture.h"
#include "XCEngine/RHI/OpenGL/OpenGLDevice.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;
const bool initResult = device->Initialize(desc);
ASSERT_TRUE(initResult);
device->Shutdown();
delete device;
}
TEST_P(RHITestFixture, Device_Initialize_OpenGLUnifiedPath_CanCreateSwapChain) {
if (GetBackendType() != RHIType::OpenGL) {
GTEST_SKIP() << "OpenGL-specific unified initialization verification";
}
auto* device = new OpenGLDevice();
ASSERT_NE(device, nullptr);
RHIDeviceDesc deviceDesc = {};
ASSERT_TRUE(device->Initialize(deviceDesc));
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = device->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
SwapChainDesc swapDesc = {};
swapDesc.windowHandle = GetWindowHandle();
swapDesc.width = 320;
swapDesc.height = 180;
RHISwapChain* swapChain = device->CreateSwapChain(swapDesc, queue);
ASSERT_NE(swapChain, nullptr);
swapChain->Present(0, 0);
swapChain->Shutdown();
delete swapChain;
queue->Shutdown();
delete queue;
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);
}