-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
6,261 additions
and
6,261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,66 @@ | ||
using System.Collections.Generic; | ||
using NSubstitute; | ||
using Windows.Win32; | ||
using Windows.Win32.UI.Accessibility; | ||
|
||
namespace Whim.TestUtils; | ||
|
||
internal class WindowManagerFakeSafeHandle : UnhookWinEventSafeHandle | ||
{ | ||
public bool HasDisposed { get; set; } | ||
|
||
private bool _isInvalid; | ||
public override bool IsInvalid => _isInvalid; | ||
|
||
public WindowManagerFakeSafeHandle(bool isInvalid, bool isClosed) | ||
: base(default, default) | ||
{ | ||
_isInvalid = isInvalid; | ||
|
||
if (isClosed) | ||
{ | ||
Close(); | ||
} | ||
} | ||
|
||
public void MarkAsInvalid() => _isInvalid = true; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
return true; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
HasDisposed = true; | ||
base.Dispose(disposing); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Captures the <see cref="WINEVENTPROC"/> passed to <see cref="CoreNativeManager.SetWinEventHook(uint, uint, WINEVENTPROC)"/>, | ||
/// and stores the <see cref="WindowManagerFakeSafeHandle"/> returned by <see cref="CoreNativeManager.SetWinEventHook(uint, uint, WINEVENTPROC)"/>. | ||
/// </summary> | ||
internal class CaptureWinEventProc | ||
{ | ||
public WINEVENTPROC? WinEventProc { get; private set; } | ||
public List<WindowManagerFakeSafeHandle> Handles { get; } = new(); | ||
|
||
public static CaptureWinEventProc Create( | ||
IInternalContext internalCtx, | ||
bool isInvalid = false, | ||
bool isClosed = false | ||
) | ||
{ | ||
CaptureWinEventProc capture = new(); | ||
internalCtx | ||
.CoreNativeManager.SetWinEventHook(Arg.Any<uint>(), Arg.Any<uint>(), Arg.Any<WINEVENTPROC>()) | ||
.Returns(callInfo => | ||
{ | ||
capture.WinEventProc = callInfo.ArgAt<WINEVENTPROC>(2); | ||
capture.Handles.Add(new WindowManagerFakeSafeHandle(isInvalid, isClosed)); | ||
return capture.Handles[^1]; | ||
}); | ||
return capture; | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using NSubstitute; | ||
using Windows.Win32; | ||
using Windows.Win32.UI.Accessibility; | ||
|
||
namespace Whim.TestUtils; | ||
|
||
internal class WindowManagerFakeSafeHandle : UnhookWinEventSafeHandle | ||
{ | ||
public bool HasDisposed { get; set; } | ||
|
||
private bool _isInvalid; | ||
public override bool IsInvalid => _isInvalid; | ||
|
||
public WindowManagerFakeSafeHandle(bool isInvalid, bool isClosed) | ||
: base(default, default) | ||
{ | ||
_isInvalid = isInvalid; | ||
|
||
if (isClosed) | ||
{ | ||
Close(); | ||
} | ||
} | ||
|
||
public void MarkAsInvalid() => _isInvalid = true; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
return true; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
HasDisposed = true; | ||
base.Dispose(disposing); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Captures the <see cref="WINEVENTPROC"/> passed to <see cref="CoreNativeManager.SetWinEventHook(uint, uint, WINEVENTPROC)"/>, | ||
/// and stores the <see cref="WindowManagerFakeSafeHandle"/> returned by <see cref="CoreNativeManager.SetWinEventHook(uint, uint, WINEVENTPROC)"/>. | ||
/// </summary> | ||
internal class CaptureWinEventProc | ||
{ | ||
public WINEVENTPROC? WinEventProc { get; private set; } | ||
public List<WindowManagerFakeSafeHandle> Handles { get; } = new(); | ||
|
||
public static CaptureWinEventProc Create( | ||
IInternalContext internalCtx, | ||
bool isInvalid = false, | ||
bool isClosed = false | ||
) | ||
{ | ||
CaptureWinEventProc capture = new(); | ||
internalCtx | ||
.CoreNativeManager.SetWinEventHook(Arg.Any<uint>(), Arg.Any<uint>(), Arg.Any<WINEVENTPROC>()) | ||
.Returns(callInfo => | ||
{ | ||
capture.WinEventProc = callInfo.ArgAt<WINEVENTPROC>(2); | ||
capture.Handles.Add(new WindowManagerFakeSafeHandle(isInvalid, isClosed)); | ||
return capture.Handles[^1]; | ||
}); | ||
return capture; | ||
} | ||
} |
46 changes: 23 additions & 23 deletions
46
src/Whim.Tests/Store/RootSector/Transforms/MouseLeftButtonDownTransformTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
using Whim.TestUtils; | ||
using Xunit; | ||
|
||
namespace Whim.Tests; | ||
|
||
public class MouseLeftButtonDownTransformTests | ||
{ | ||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void Success(IContext ctx, MutableRootSector mutableRootSector) | ||
{ | ||
// Given the left mouse button is down | ||
mutableRootSector.WindowSector.IsLeftMouseButtonDown = true; | ||
|
||
MouseLeftButtonDownTransform sut = new(); | ||
|
||
// When | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then the left mouse button is longer down | ||
Assert.True(result.IsSuccessful); | ||
Assert.True(mutableRootSector.WindowSector.IsLeftMouseButtonDown); | ||
} | ||
} | ||
using Whim.TestUtils; | ||
using Xunit; | ||
|
||
namespace Whim.Tests; | ||
|
||
public class MouseLeftButtonDownTransformTests | ||
{ | ||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void Success(IContext ctx, MutableRootSector mutableRootSector) | ||
{ | ||
// Given the left mouse button is down | ||
mutableRootSector.WindowSector.IsLeftMouseButtonDown = true; | ||
|
||
MouseLeftButtonDownTransform sut = new(); | ||
|
||
// When | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then the left mouse button is longer down | ||
Assert.True(result.IsSuccessful); | ||
Assert.True(mutableRootSector.WindowSector.IsLeftMouseButtonDown); | ||
} | ||
} |
198 changes: 99 additions & 99 deletions
198
src/Whim.Tests/Store/WindowSector/Transforms/WindowAddedTransformTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,99 @@ | ||
using System.ComponentModel; | ||
using NSubstitute; | ||
using NSubstitute.ExceptionExtensions; | ||
using Whim.TestUtils; | ||
using Windows.Win32.Foundation; | ||
using Xunit; | ||
|
||
namespace Whim.Tests; | ||
|
||
public class WindowAddedTransformTests | ||
{ | ||
private static void Setup( | ||
IContext ctx, | ||
IInternalContext internalCtx, | ||
HWND hwnd, | ||
bool isSplashScreen = false, | ||
bool isCloakedWindow = false, | ||
bool isNotStandardWindow = false, | ||
bool hasVisibleWindow = false, | ||
bool cannotCreateWindow = false, | ||
bool shouldBeIgnored = false | ||
) | ||
{ | ||
internalCtx.CoreNativeManager.IsSplashScreen(hwnd).Returns(isSplashScreen); | ||
internalCtx.CoreNativeManager.IsCloakedWindow(hwnd).Returns(isCloakedWindow); | ||
internalCtx.CoreNativeManager.IsStandardWindow(hwnd).Returns(!isNotStandardWindow); | ||
internalCtx.CoreNativeManager.HasNoVisibleOwner(hwnd).Returns(!hasVisibleWindow); | ||
|
||
if (cannotCreateWindow) | ||
{ | ||
internalCtx.CoreNativeManager.GetProcessNameAndPath(Arg.Any<int>()).Throws(new Win32Exception()); | ||
} | ||
else | ||
{ | ||
internalCtx | ||
.CoreNativeManager.GetProcessNameAndPath(Arg.Any<int>()) | ||
.Returns(("processName", "processFileName")); | ||
} | ||
|
||
ctx.FilterManager.ShouldBeIgnored(Arg.Any<IWindow>()).Returns(shouldBeIgnored); | ||
} | ||
|
||
[InlineAutoSubstituteData<StoreCustomization>("IsSplashScreen", true, false, false, false, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("IsCloakedWindow", false, true, false, false, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("IsStandardWindow", false, false, true, false, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("HasNoVisibleWindow", false, false, false, true, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("CannotCreateWindow", false, false, false, false, true, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("ShouldBeIgnored", false, false, false, false, false, true)] | ||
[Theory] | ||
internal void Failure( | ||
string _, | ||
bool isSplashScreen, | ||
bool isCloakedWindow, | ||
bool isNotStandardWindow, | ||
bool hasNoVisibleWindow, | ||
bool cannotCreateWindow, | ||
bool shouldBeIgnored, | ||
IContext ctx, | ||
IInternalContext internalCtx | ||
) | ||
{ | ||
// Given the handle fails | ||
HWND hwnd = (HWND)1; | ||
Setup( | ||
ctx, | ||
internalCtx, | ||
hwnd, | ||
isSplashScreen, | ||
isCloakedWindow, | ||
isNotStandardWindow, | ||
hasNoVisibleWindow, | ||
cannotCreateWindow, | ||
shouldBeIgnored | ||
); | ||
WindowAddedTransform sut = new(hwnd); | ||
|
||
// When we dispatch the transform | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then we received an error | ||
Assert.False(result.IsSuccessful); | ||
} | ||
|
||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void Success(IContext ctx, IInternalContext internalCtx) | ||
{ | ||
// Given the handle succeeds | ||
HWND hwnd = (HWND)1; | ||
Setup(ctx, internalCtx, hwnd); | ||
WindowAddedTransform sut = new(hwnd); | ||
|
||
// When we dispatch the transform | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then we receive the window | ||
Assert.True(result.IsSuccessful); | ||
Assert.IsAssignableFrom<IWindow>(result.Value); | ||
} | ||
} | ||
using System.ComponentModel; | ||
using NSubstitute; | ||
using NSubstitute.ExceptionExtensions; | ||
using Whim.TestUtils; | ||
using Windows.Win32.Foundation; | ||
using Xunit; | ||
|
||
namespace Whim.Tests; | ||
|
||
public class WindowAddedTransformTests | ||
{ | ||
private static void Setup( | ||
IContext ctx, | ||
IInternalContext internalCtx, | ||
HWND hwnd, | ||
bool isSplashScreen = false, | ||
bool isCloakedWindow = false, | ||
bool isNotStandardWindow = false, | ||
bool hasVisibleWindow = false, | ||
bool cannotCreateWindow = false, | ||
bool shouldBeIgnored = false | ||
) | ||
{ | ||
internalCtx.CoreNativeManager.IsSplashScreen(hwnd).Returns(isSplashScreen); | ||
internalCtx.CoreNativeManager.IsCloakedWindow(hwnd).Returns(isCloakedWindow); | ||
internalCtx.CoreNativeManager.IsStandardWindow(hwnd).Returns(!isNotStandardWindow); | ||
internalCtx.CoreNativeManager.HasNoVisibleOwner(hwnd).Returns(!hasVisibleWindow); | ||
|
||
if (cannotCreateWindow) | ||
{ | ||
internalCtx.CoreNativeManager.GetProcessNameAndPath(Arg.Any<int>()).Throws(new Win32Exception()); | ||
} | ||
else | ||
{ | ||
internalCtx | ||
.CoreNativeManager.GetProcessNameAndPath(Arg.Any<int>()) | ||
.Returns(("processName", "processFileName")); | ||
} | ||
|
||
ctx.FilterManager.ShouldBeIgnored(Arg.Any<IWindow>()).Returns(shouldBeIgnored); | ||
} | ||
|
||
[InlineAutoSubstituteData<StoreCustomization>("IsSplashScreen", true, false, false, false, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("IsCloakedWindow", false, true, false, false, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("IsStandardWindow", false, false, true, false, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("HasNoVisibleWindow", false, false, false, true, false, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("CannotCreateWindow", false, false, false, false, true, false)] | ||
[InlineAutoSubstituteData<StoreCustomization>("ShouldBeIgnored", false, false, false, false, false, true)] | ||
[Theory] | ||
internal void Failure( | ||
string _, | ||
bool isSplashScreen, | ||
bool isCloakedWindow, | ||
bool isNotStandardWindow, | ||
bool hasNoVisibleWindow, | ||
bool cannotCreateWindow, | ||
bool shouldBeIgnored, | ||
IContext ctx, | ||
IInternalContext internalCtx | ||
) | ||
{ | ||
// Given the handle fails | ||
HWND hwnd = (HWND)1; | ||
Setup( | ||
ctx, | ||
internalCtx, | ||
hwnd, | ||
isSplashScreen, | ||
isCloakedWindow, | ||
isNotStandardWindow, | ||
hasNoVisibleWindow, | ||
cannotCreateWindow, | ||
shouldBeIgnored | ||
); | ||
WindowAddedTransform sut = new(hwnd); | ||
|
||
// When we dispatch the transform | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then we received an error | ||
Assert.False(result.IsSuccessful); | ||
} | ||
|
||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void Success(IContext ctx, IInternalContext internalCtx) | ||
{ | ||
// Given the handle succeeds | ||
HWND hwnd = (HWND)1; | ||
Setup(ctx, internalCtx, hwnd); | ||
WindowAddedTransform sut = new(hwnd); | ||
|
||
// When we dispatch the transform | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then we receive the window | ||
Assert.True(result.IsSuccessful); | ||
Assert.IsAssignableFrom<IWindow>(result.Value); | ||
} | ||
} |
Oops, something went wrong.