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

123 lines
3.4 KiB
C++
Raw Normal View History

#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.mipLevels = 1;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
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);
}