Add unit test for multiple device removals

このコミットが含まれているのは:
Sergio Pedri committed 2022-07-31 23:26:14 +02:00
1 親 22fccc032c
コミット f1306a4621
2ファイル変更
+36 -23

検索条件に一致するファイルはありません

+9
ファイルの表示
@@ -30,6 +30,15 @@ public class DeviceLostTests
Assert.IsNotNull(args[0].Reason);
Assert.AreSame(args[0].Sender, graphicsDevice);
Assert.AreEqual(args[0].Reason, DeviceLostReason.DeviceRemoved);
// Trying to remove the device again does nothing
GraphicsDeviceHelper.RemoveDevice(graphicsDevice);
GraphicsDeviceHelper.RemoveDevice(graphicsDevice);
GraphicsDeviceHelper.RemoveDevice(graphicsDevice);
GraphicsDeviceHelper.RemoveDevice(graphicsDevice);
// The event can only be raised once
Assert.AreEqual(1, args.Count);
}
[CombinatorialTestMethod]
+27 -23
ファイルの表示
@@ -45,6 +45,33 @@ internal static class GraphicsDeviceHelper
return d3D12Device.Get()->Release();
}
/// <summary>
/// Removes the underlying device for a given <see cref="GraphicsDevice"/> instance.
/// </summary>
/// <param name="graphicsDevice">The target <see cref="GraphicsDevice"/> instance.</param>
public static unsafe void RemoveDevice(GraphicsDevice graphicsDevice)
{
ID3D12Device5* d3D12Device = default;
Guid d3D12Device5Guid = typeof(ID3D12Device5).GUID;
if (InteropServices.TryGetID3D12Device(graphicsDevice, &d3D12Device5Guid, (void**)&d3D12Device) != 0)
{
Assert.Inconclusive();
}
try
{
d3D12Device->RemoveDevice();
}
finally
{
if (d3D12Device is not null)
{
d3D12Device->Release();
}
}
}
/// <summary>
/// Removes the underlying device for a given <see cref="GraphicsDevice"/> instance and waits for it to be reported.
/// </summary>
@@ -62,29 +89,6 @@ internal static class GraphicsDeviceHelper
graphicsDevice.DeviceLost += (s, e) => tcs.SetResult(null);
static unsafe void RemoveDevice(GraphicsDevice graphicsDevice)
{
ID3D12Device5* d3D12Device = default;
Guid d3D12Device5Guid = typeof(ID3D12Device5).GUID;
if (InteropServices.TryGetID3D12Device(graphicsDevice, &d3D12Device5Guid, (void**)&d3D12Device) != 0)
{
Assert.Inconclusive();
}
try
{
d3D12Device->RemoveDevice();
}
finally
{
if (d3D12Device is not null)
{
d3D12Device->Release();
}
}
}
RemoveDevice(graphicsDevice);
await tcs.Task;