Skip to content

Commit

Permalink
Add WindowsBase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hughbe committed Apr 28, 2024
1 parent ed86673 commit 69a8dcb
Show file tree
Hide file tree
Showing 93 changed files with 48,397 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Microsoft.Dotnet.Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluent", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Fluent\PresentationFramework.Fluent.csproj", "{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluent-ref", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Fluent\ref\PresentationFramework.Fluent-ref.csproj", "{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}"
Project("{6FFF8BB3-74D1-4860-BEF1-5B307BCDBB95}") = "WindowsBase.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\WindowsBase.Tests\WindowsBase.Tests.csproj", "{A5DC575D-EC10-445B-94C1-98015F926FFA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -1978,6 +1979,28 @@ Global
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x64.Build.0 = Release|x64
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x86.ActiveCfg = Release|Any CPU
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x86.Build.0 = Release|Any CPU
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.ActiveCfg = Debug|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.Build.0 = Debug|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.Deploy.0 = Debug|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|ARM64.ActiveCfg = Debug|ARM64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|ARM64.Build.0 = Debug|ARM64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.ActiveCfg = Debug|x64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.Build.0 = Debug|x64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.Deploy.0 = Debug|x64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.ActiveCfg = Debug|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.Build.0 = Debug|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.Deploy.0 = Debug|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.ActiveCfg = Release|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.Build.0 = Release|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.Deploy.0 = Release|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|ARM64.ActiveCfg = Release|ARM64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|ARM64.Build.0 = Release|ARM64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.ActiveCfg = Release|x64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.Build.0 = Release|x64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.Deploy.0 = Release|x64
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.ActiveCfg = Release|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.Build.0 = Release|Win32
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.Deploy.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2100,6 +2123,7 @@ Global
{B2F2A89C-55C9-41B1-A645-0948609BD8BE} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9} = {5ACFB055-649D-4A01-98C2-B0BFE7E543D6}
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD} = {60F4058B-D35B-42D2-B276-D44B3AC579BD}
{A5DC575D-EC10-445B-94C1-98015F926FFA} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4340004-DAC0-497D-B69D-CFA7CD93F567}
Expand Down
125 changes: 125 additions & 0 deletions src/Microsoft.DotNet.Wpf/tests/UnitTests/WindowsBase.Tests/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Media;
using Xunit.Sdk;

public static class Helpers
{
#pragma warning disable xUnit1013
public static string GetResourcePath(string name) => Path.GetFullPath(Path.Combine("Resources", name));

public static void ExecuteOnDifferentThread(Action action, ApartmentState? state = null)
{
ExceptionDispatchInfo? edi = null;
var t = new Thread(() =>
{
try
{
action();
}
catch (Exception e)
{
edi = ExceptionDispatchInfo.Capture(e);
}
});
if (state is not null)
{
t.SetApartmentState(state.Value);
}
t.Start();
t.Join();

if (edi is not null)
{
edi.Throw();
}
}

public static T ExecuteOnDifferentThread<T>(Func<T> action, ApartmentState? state = null)
{
T? result = default;
ExceptionDispatchInfo? edi = null;
var t = new Thread(() =>
{
try
{
result = action();
}
catch (Exception e)
{
edi = ExceptionDispatchInfo.Capture(e);
}
});
if (state is not null)
{
t.SetApartmentState(state.Value);
}
t.Start();
t.Join();

if (edi is not null)
{
edi.Throw();
throw new Exception("Not reachable.");
}
else
{
return result!;
}
}

public static void AssertEqualRounded(Matrix expected, Matrix actual, int precision = 5)
{
if (expected.Equals(actual))
{
return;
}

try
{
Assert.Equal(expected.M11, actual.M11, precision);
Assert.Equal(expected.M12, actual.M12, precision);
Assert.Equal(expected.M21, actual.M21, precision);
Assert.Equal(expected.M22, actual.M22, precision);
Assert.Equal(expected.OffsetX, actual.OffsetX, precision);
Assert.Equal(expected.OffsetY, actual.OffsetY, precision);
}
catch (Exception)
{
// Throw main AssertException with formatting.
//Assert.Equal(expected, actual);
}
}

public static void AssertEqualRounded(Rect expected, Rect actual, int precision)
{
if (expected.Equals(actual))
{
return;
}

try
{
Assert.Equal(expected.X, actual.X, precision);
Assert.Equal(expected.Y, actual.Y, precision);
Assert.Equal(expected.Width, actual.Width, precision);
Assert.Equal(expected.Height, actual.Height, precision);
}
catch (Exception)
{
// Throw main AssertException with formatting.
Assert.Equal(expected, actual);
}
}
#pragma warning restore xUnit1013
}
Loading

0 comments on commit 69a8dcb

Please sign in to comment.