#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); bool initResult = false; if (GetBackendType() == RHIType::D3D12) { RHIDeviceDesc desc = {}; desc.enableDebugLayer = true; initResult = device->Initialize(desc); } else if (GetBackendType() == RHIType::OpenGL) { auto* oglDevice = static_cast(device); initResult = oglDevice->InitializeWithExistingWindow(GetWindowHandle()); } 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(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(Format::R8G8B8A8_UNorm); desc.textureType = static_cast(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(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(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(FilterMode::Linear); desc.addressU = static_cast(TextureAddressMode::Wrap); desc.addressV = static_cast(TextureAddressMode::Wrap); desc.addressW = static_cast(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); }