Skip to content

Commit

Permalink
Normalize line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
dalyIsaac committed Jun 9, 2024
1 parent a2ff941 commit 626bede
Show file tree
Hide file tree
Showing 35 changed files with 6,261 additions and 6,261 deletions.
132 changes: 66 additions & 66 deletions src/Whim.TestUtils/CaptureWinEventProc.cs
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; }

Check warning on line 10 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L10

Added line #L10 was not covered by tests

private bool _isInvalid;
public override bool IsInvalid => _isInvalid;

Check warning on line 13 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L13

Added line #L13 was not covered by tests

public WindowManagerFakeSafeHandle(bool isInvalid, bool isClosed)
: base(default, default)
{
_isInvalid = isInvalid;

Check warning on line 18 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L16-L18

Added lines #L16 - L18 were not covered by tests

if (isClosed)
{
Close();
}
}

Check warning on line 24 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L21-L24

Added lines #L21 - L24 were not covered by tests

public void MarkAsInvalid() => _isInvalid = true;

Check warning on line 26 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L26

Added line #L26 was not covered by tests

protected override bool ReleaseHandle()
{
return true;
}

Check warning on line 31 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L29-L31

Added lines #L29 - L31 were not covered by tests

protected override void Dispose(bool disposing)
{
HasDisposed = true;
base.Dispose(disposing);
}

Check warning on line 37 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L34-L37

Added lines #L34 - L37 were not covered by tests
}

/// <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();

Check warning on line 47 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L46-L47

Added lines #L46 - L47 were not covered by tests

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;
}

Check warning on line 65 in src/Whim.TestUtils/CaptureWinEventProc.cs

View check run for this annotation

Codecov / codecov/patch

src/Whim.TestUtils/CaptureWinEventProc.cs#L54-L65

Added lines #L54 - L65 were not covered by tests
}
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);
}
}
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);
}
}
Loading

0 comments on commit 626bede

Please sign in to comment.