Skip to content

Commit

Permalink
Moved code shared with PowerToys MouseJump into "Common" folder for e…
Browse files Browse the repository at this point in the history
…asier synching
  • Loading branch information
mikeclayton committed Apr 25, 2024
1 parent 79835f9 commit a31135b
Show file tree
Hide file tree
Showing 172 changed files with 894 additions and 615 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using FancyMouse.Helpers;
using FancyMouse.Helpers.Screenshot;
using FancyMouse.Models.Drawing;
using FancyMouse.Common.Helpers;
using FancyMouse.Common.Imaging;
using FancyMouse.Common.Models.Drawing;
using FancyMouse.Common.Models.Styles;
using FancyMouse.Models.Settings;
using FancyMouse.Models.Styles;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FancyMouse.UnitTests.Helpers;
namespace FancyMouse.UnitTests.Common.Helpers;

[TestClass]
public static class DrawingHelperTests
Expand Down Expand Up @@ -53,8 +52,8 @@ public static IEnumerable<object[]> GetTestCases()
new RectangleInfo(0, 500, 500, 500),
},
activatedLocation: new(x: 50, y: 50),
desktopImageFilename: "Helpers/_test-4grid-desktop.png",
expectedImageFilename: "Helpers/_test-4grid-expected.png"),
desktopImageFilename: "Common/Helpers/_test-4grid-desktop.png",
expectedImageFilename: "Common/Helpers/_test-4grid-expected.png"),
};
/* win 11 */
yield return new object[]
Expand All @@ -67,8 +66,8 @@ public static IEnumerable<object[]> GetTestCases()
new RectangleInfo(0, 0, 5120, 1440),
},
activatedLocation: new(x: 50, y: 50),
desktopImageFilename: "Helpers/_test-win11-desktop.png",
expectedImageFilename: "Helpers/_test-win11-expected.png"),
desktopImageFilename: "Common/Helpers/_test-win11-desktop.png",
expectedImageFilename: "Common/Helpers/_test-win11-expected.png"),
};
}

Expand All @@ -84,8 +83,8 @@ public void RunTestCases(TestCase data)
previewStyle: data.PreviewStyle,
screens: data.Screens,
activatedLocation: data.ActivatedLocation);
var screenshotProvider = new ImageScreenshotProvider(desktopImage);
using var actual = DrawingHelper.RenderPreview(previewLayout, screenshotProvider);
var imageCopyService = new StaticImageRegionCopyService(desktopImage);
using var actual = DrawingHelper.RenderPreview(previewLayout, imageCopyService);

// load the expected image
var expected = GetPreviewLayoutTests.LoadImageResource(data.ExpectedImageFilename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Drawing;
using System.Text.Json;
using FancyMouse.Helpers;
using FancyMouse.Models.Drawing;
using FancyMouse.Models.Layout;
using FancyMouse.Models.Styles;
using FancyMouse.Common.Helpers;
using FancyMouse.Common.Models.Drawing;
using FancyMouse.Common.Models.Layout;
using FancyMouse.Common.Models.Styles;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FancyMouse.UnitTests.Helpers;
namespace FancyMouse.UnitTests.Common.Helpers;

[TestClass]
public static class LayoutHelperTests
Expand Down Expand Up @@ -149,7 +149,7 @@ public static IEnumerable<object[]> GetTestCases()
color2: Color.FromArgb(3, 68, 192) // darker blue
)
),
screenshotStyle: BoxStyle.Empty);
screenStyle: BoxStyle.Empty);
var screens = new List<RectangleInfo>
{
new(0, 0, 1024, 768),
Expand Down Expand Up @@ -193,7 +193,7 @@ public static IEnumerable<object[]> GetTestCases()
height: 384
),
canvasStyle: BoxStyle.Empty,
screenshotStyle: new(
screenStyle: new(
marginStyle: new(
all: 1),
borderStyle: new(
Expand Down Expand Up @@ -266,7 +266,7 @@ public static IEnumerable<object[]> GetTestCases()
color2: Color.FromArgb(3, 68, 192) // darker blue
)
),
screenshotStyle: new(
screenStyle: new(
marginStyle: new(
all: 1),
borderStyle: new(
Expand Down
69 changes: 69 additions & 0 deletions src/FancyMouse.UnitTests/Common/Helpers/MouseHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using FancyMouse.Common.Helpers;
using FancyMouse.Common.Models.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FancyMouse.UnitTests.Common.Helpers;

[TestClass]
public static class MouseHelperTests
{
[TestClass]
public sealed class GetJumpLocationTests
{
public sealed class TestCase
{
public TestCase(PointInfo previewLocation, SizeInfo previewSize, RectangleInfo desktopBounds, PointInfo expectedResult)
{
this.PreviewLocation = previewLocation;
this.PreviewSize = previewSize;
this.DesktopBounds = desktopBounds;
this.ExpectedResult = expectedResult;
}

public PointInfo PreviewLocation { get; }

public SizeInfo PreviewSize { get; }

public RectangleInfo DesktopBounds { get; }

public PointInfo ExpectedResult { get; }
}

public static IEnumerable<object[]> GetTestCases()
{
// screen corners and midpoint with a zero origin
yield return new object[] { new TestCase(new(0, 0), new(160, 120), new(0, 0, 1600, 1200), new(0, 0)) };
yield return new object[] { new TestCase(new(160, 0), new(160, 120), new(0, 0, 1600, 1200), new(1600, 0)) };
yield return new object[] { new TestCase(new(0, 120), new(160, 120), new(0, 0, 1600, 1200), new(0, 1200)) };
yield return new object[] { new TestCase(new(160, 120), new(160, 120), new(0, 0, 1600, 1200), new(1600, 1200)) };
yield return new object[] { new TestCase(new(80, 60), new(160, 120), new(0, 0, 1600, 1200), new(800, 600)) };

// screen corners and midpoint with a positive origin
yield return new object[] { new TestCase(new(0, 0), new(160, 120), new(1000, 1000, 1600, 1200), new(1000, 1000)) };
yield return new object[] { new TestCase(new(160, 0), new(160, 120), new(1000, 1000, 1600, 1200), new(2600, 1000)) };
yield return new object[] { new TestCase(new(0, 120), new(160, 120), new(1000, 1000, 1600, 1200), new(1000, 2200)) };
yield return new object[] { new TestCase(new(160, 120), new(160, 120), new(1000, 1000, 1600, 1200), new(2600, 2200)) };
yield return new object[] { new TestCase(new(80, 60), new(160, 120), new(1000, 1000, 1600, 1200), new(1800, 1600)) };

// screen corners and midpoint with a negative origin
yield return new object[] { new TestCase(new(0, 0), new(160, 120), new(-1000, -1000, 1600, 1200), new(-1000, -1000)) };
yield return new object[] { new TestCase(new(160, 0), new(160, 120), new(-1000, -1000, 1600, 1200), new(600, -1000)) };
yield return new object[] { new TestCase(new(0, 120), new(160, 120), new(-1000, -1000, 1600, 1200), new(-1000, 200)) };
yield return new object[] { new TestCase(new(160, 120), new(160, 120), new(-1000, -1000, 1600, 1200), new(600, 200)) };
yield return new object[] { new TestCase(new(80, 60), new(160, 120), new(-1000, -1000, 1600, 1200), new(-200, -400)) };
}

[TestMethod]
[DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)]
public void RunTestCases(TestCase data)
{
var actual = MouseHelper.GetJumpLocation(
data.PreviewLocation,
data.PreviewSize,
data.DesktopBounds);
var expected = data.ExpectedResult;
Assert.AreEqual(expected.X, actual.X);
Assert.AreEqual(expected.Y, actual.Y);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FancyMouse.Models.Drawing;
using FancyMouse.Common.Models.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FancyMouse.UnitTests.Models.Drawing;
namespace FancyMouse.UnitTests.Common.Models.Drawing;

[TestClass]
public static class RectangleInfoTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FancyMouse.Models.Drawing;
using FancyMouse.Common.Models.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FancyMouse.UnitTests.Models.Drawing;
namespace FancyMouse.UnitTests.Common.Models.Drawing;

[TestClass]
public static class SizeInfoTests
Expand Down
16 changes: 8 additions & 8 deletions src/FancyMouse.UnitTests/FancyMouse.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Helpers\_test-4grid-desktop.png" />
<None Remove="Helpers\_test-4grid-expected.png" />
<None Remove="Helpers\_test-win11-desktop.png" />
<None Remove="Helpers\_test-win11-expected.png" />
<None Remove="Common\Helpers\_test-4grid-desktop.png" />
<None Remove="Common\Helpers\_test-4grid-expected.png" />
<None Remove="Common\Helpers\_test-win11-desktop.png" />
<None Remove="Common\Helpers\_test-win11-expected.png" />
</ItemGroup>

<ItemGroup>
Expand All @@ -24,10 +24,10 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Helpers\_test-4grid-desktop.png" />
<EmbeddedResource Include="Helpers\_test-4grid-expected.png" />
<EmbeddedResource Include="Helpers\_test-win11-desktop.png" />
<EmbeddedResource Include="Helpers\_test-win11-expected.png" />
<EmbeddedResource Include="Common\Helpers\_test-4grid-desktop.png" />
<EmbeddedResource Include="Common\Helpers\_test-4grid-expected.png" />
<EmbeddedResource Include="Common\Helpers\_test-win11-desktop.png" />
<EmbeddedResource Include="Common\Helpers\_test-win11-expected.png" />
</ItemGroup>

<ItemGroup>
Expand Down
69 changes: 0 additions & 69 deletions src/FancyMouse.UnitTests/Helpers/MouseHelperTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Diagnostics;
using System.Drawing;
using System.Text.Json;
using FancyMouse.Common.Models.Styles;
using FancyMouse.HotKeys;
using FancyMouse.Models.Settings;
using FancyMouse.Models.Styles;
using FancyMouse.UnitTests.TestUtils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -124,7 +124,7 @@ public void Version1WithAllValuesShouldParse()
height: 600
),
canvasStyle: AppSettings.DefaultSettings.PreviewStyle.CanvasStyle,
screenshotStyle: AppSettings.DefaultSettings.PreviewStyle.ScreenshotStyle
screenStyle: AppSettings.DefaultSettings.PreviewStyle.ScreenStyle
));
Assert.AreEqual(
JsonSerializer.Serialize(expected),
Expand Down Expand Up @@ -227,7 +227,7 @@ public void Version2WithAllValuesShouldParse()
color2: Color.Blue
)
),
screenshotStyle: new(
screenStyle: new(
marginStyle: new(
all: 10
),
Expand Down
Loading

0 comments on commit a31135b

Please sign in to comment.