Skip to content

Commit

Permalink
tests: Add IDXGIAdapter3 mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jp7677 committed Aug 15, 2024
1 parent 84bde44 commit 3fa7e84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
9 changes: 8 additions & 1 deletion tests/nvapi_sysinfo_mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DXGIDxvkFactoryMock final : public trompeloeil::mock_interface<IDXGIDxvkFa
IMPLEMENT_MOCK2(SetGlobalHDRState);
};

class IDXGIDxvkAdapter : public IDXGIAdapter1, public IDXGIVkInteropAdapter {};
class IDXGIDxvkAdapter : public IDXGIAdapter3, public IDXGIVkInteropAdapter {};

class DXGIDxvkAdapterMock final : public trompeloeil::mock_interface<IDXGIDxvkAdapter> {
MAKE_MOCK2(QueryInterface, HRESULT(REFIID, void**), override);
Expand All @@ -42,6 +42,13 @@ class DXGIDxvkAdapterMock final : public trompeloeil::mock_interface<IDXGIDxvkAd
IMPLEMENT_MOCK2(CheckInterfaceSupport);
IMPLEMENT_MOCK1(GetDesc1);
IMPLEMENT_MOCK2(GetVulkanHandles);
IMPLEMENT_MOCK1(GetDesc2);
IMPLEMENT_MOCK2(RegisterHardwareContentProtectionTeardownStatusEvent);
IMPLEMENT_MOCK1(UnregisterHardwareContentProtectionTeardownStatus);
IMPLEMENT_MOCK3(QueryVideoMemoryInfo);
IMPLEMENT_MOCK3(SetVideoMemoryReservation);
IMPLEMENT_MOCK2(RegisterVideoMemoryBudgetChangeNotificationEvent);
IMPLEMENT_MOCK1(UnregisterVideoMemoryBudgetChangeNotification);
};

class DXGIOutput6Mock final : public trompeloeil::mock_interface<IDXGIOutput6> {
Expand Down
19 changes: 17 additions & 2 deletions tests/resource_factory_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ResetGlobals() {
initializationCount = 0ULL;
}

[[nodiscard]] std::array<std::unique_ptr<expectation>, 22> ConfigureDefaultTestEnvironment(
[[nodiscard]] std::array<std::unique_ptr<expectation>, 24> ConfigureDefaultTestEnvironment(
DXGIDxvkFactoryMock& dxgiFactory,
VulkanMock& vulkan,
NvmlMock& nvml,
Expand All @@ -52,9 +52,14 @@ void ResetGlobals() {
NAMED_ALLOW_CALL(dxgiFactory, SetGlobalHDRState(_, _))
.RETURN(S_OK),

NAMED_ALLOW_CALL(adapter, QueryInterface(__uuidof(IDXGIAdapter3), _))
.LR_SIDE_EFFECT(*_2 = static_cast<IDXGIAdapter3*>(&adapter))
.RETURN(S_OK),
NAMED_ALLOW_CALL(adapter, QueryInterface(__uuidof(IDXGIVkInteropAdapter), _))
.LR_SIDE_EFFECT(*_2 = static_cast<IDXGIVkInteropAdapter*>(&adapter))
.RETURN(S_OK),
NAMED_ALLOW_CALL(adapter, AddRef())
.RETURN(1),
NAMED_ALLOW_CALL(adapter, Release())
.RETURN(0),
NAMED_ALLOW_CALL(adapter, GetDesc1(_))
Expand Down Expand Up @@ -95,7 +100,7 @@ void ResetGlobals() {
.RETURN(false)};
}

[[nodiscard]] std::array<std::unique_ptr<expectation>, 37> ConfigureExtendedTestEnvironment(
[[nodiscard]] std::array<std::unique_ptr<expectation>, 41> ConfigureExtendedTestEnvironment(
DXGIDxvkFactoryMock& dxgiFactory,
VulkanMock& vulkan,
NvmlMock& nvml,
Expand Down Expand Up @@ -127,9 +132,14 @@ void ResetGlobals() {
NAMED_ALLOW_CALL(dxgiFactory, SetGlobalHDRState(_, _))
.RETURN(S_OK),

NAMED_ALLOW_CALL(adapter1, QueryInterface(__uuidof(IDXGIAdapter3), _))
.LR_SIDE_EFFECT(*_2 = static_cast<IDXGIAdapter3*>(&adapter1))
.RETURN(S_OK),
NAMED_ALLOW_CALL(adapter1, QueryInterface(__uuidof(IDXGIVkInteropAdapter), _))
.LR_SIDE_EFFECT(*_2 = static_cast<IDXGIVkInteropAdapter*>(&adapter1))
.RETURN(S_OK),
NAMED_ALLOW_CALL(adapter1, AddRef())
.RETURN(1),
NAMED_ALLOW_CALL(adapter1, Release())
.RETURN(0),
NAMED_ALLOW_CALL(adapter1, GetDesc1(_))
Expand All @@ -146,9 +156,14 @@ void ResetGlobals() {
NAMED_ALLOW_CALL(adapter1, GetVulkanHandles(_, _))
.LR_SIDE_EFFECT(*_2 = reinterpret_cast<VkPhysicalDevice>(0x01)),

NAMED_ALLOW_CALL(adapter2, QueryInterface(__uuidof(IDXGIAdapter3), _))
.LR_SIDE_EFFECT(*_2 = static_cast<IDXGIAdapter3*>(&adapter2))
.RETURN(S_OK),
NAMED_ALLOW_CALL(adapter2, QueryInterface(__uuidof(IDXGIVkInteropAdapter), _))
.LR_SIDE_EFFECT(*_2 = static_cast<IDXGIVkInteropAdapter*>(&adapter2))
.RETURN(S_OK),
NAMED_ALLOW_CALL(adapter2, AddRef())
.RETURN(1),
NAMED_ALLOW_CALL(adapter2, Release())
.RETURN(0),
NAMED_ALLOW_CALL(adapter2, GetDesc1(_))
Expand Down
4 changes: 2 additions & 2 deletions tests/resource_factory_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ void SetupResourceFactory(

void ResetGlobals();

[[nodiscard]] std::array<std::unique_ptr<trompeloeil::expectation>, 22> ConfigureDefaultTestEnvironment(
[[nodiscard]] std::array<std::unique_ptr<trompeloeil::expectation>, 24> ConfigureDefaultTestEnvironment(
DXGIDxvkFactoryMock& dxgiFactory,
VulkanMock& vulkan,
NvmlMock& nvml,
LfxMock& lfx,
DXGIDxvkAdapterMock& adapter,
DXGIOutput6Mock& output);

[[nodiscard]] std::array<std::unique_ptr<trompeloeil::expectation>, 37> ConfigureExtendedTestEnvironment(
[[nodiscard]] std::array<std::unique_ptr<trompeloeil::expectation>, 41> ConfigureExtendedTestEnvironment(
DXGIDxvkFactoryMock& dxgiFactory,
VulkanMock& vulkan,
NvmlMock& nvml,
Expand Down

0 comments on commit 3fa7e84

Please sign in to comment.