Skip to content

Commit 69a8dcb

Browse files
committed
Add WindowsBase tests
1 parent ed86673 commit 69a8dcb

File tree

93 files changed

+48397
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+48397
-0
lines changed

Microsoft.Dotnet.Wpf.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ EndProject
252252
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluent", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Fluent\PresentationFramework.Fluent.csproj", "{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}"
253253
EndProject
254254
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}"
255+
Project("{6FFF8BB3-74D1-4860-BEF1-5B307BCDBB95}") = "WindowsBase.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\WindowsBase.Tests\WindowsBase.Tests.csproj", "{A5DC575D-EC10-445B-94C1-98015F926FFA}"
255256
EndProject
256257
Global
257258
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -1978,6 +1979,28 @@ Global
19781979
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x64.Build.0 = Release|x64
19791980
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x86.ActiveCfg = Release|Any CPU
19801981
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x86.Build.0 = Release|Any CPU
1982+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.ActiveCfg = Debug|Win32
1983+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.Build.0 = Debug|Win32
1984+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.Deploy.0 = Debug|Win32
1985+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|ARM64.ActiveCfg = Debug|ARM64
1986+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|ARM64.Build.0 = Debug|ARM64
1987+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.ActiveCfg = Debug|x64
1988+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.Build.0 = Debug|x64
1989+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.Deploy.0 = Debug|x64
1990+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.ActiveCfg = Debug|Win32
1991+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.Build.0 = Debug|Win32
1992+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.Deploy.0 = Debug|Win32
1993+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.ActiveCfg = Release|Win32
1994+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.Build.0 = Release|Win32
1995+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.Deploy.0 = Release|Win32
1996+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|ARM64.ActiveCfg = Release|ARM64
1997+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|ARM64.Build.0 = Release|ARM64
1998+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.ActiveCfg = Release|x64
1999+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.Build.0 = Release|x64
2000+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.Deploy.0 = Release|x64
2001+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.ActiveCfg = Release|Win32
2002+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.Build.0 = Release|Win32
2003+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.Deploy.0 = Release|Win32
19812004
EndGlobalSection
19822005
GlobalSection(SolutionProperties) = preSolution
19832006
HideSolutionNode = FALSE
@@ -2100,6 +2123,7 @@ Global
21002123
{B2F2A89C-55C9-41B1-A645-0948609BD8BE} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
21012124
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9} = {5ACFB055-649D-4A01-98C2-B0BFE7E543D6}
21022125
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD} = {60F4058B-D35B-42D2-B276-D44B3AC579BD}
2126+
{A5DC575D-EC10-445B-94C1-98015F926FFA} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
21032127
EndGlobalSection
21042128
GlobalSection(ExtensibilityGlobals) = postSolution
21052129
SolutionGuid = {B4340004-DAC0-497D-B69D-CFA7CD93F567}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Specialized;
7+
using System.ComponentModel;
8+
using System.IO;
9+
using System.Runtime.ExceptionServices;
10+
using System.Text;
11+
using System.Threading;
12+
using System.Windows;
13+
using System.Windows.Media;
14+
using Xunit.Sdk;
15+
16+
public static class Helpers
17+
{
18+
#pragma warning disable xUnit1013
19+
public static string GetResourcePath(string name) => Path.GetFullPath(Path.Combine("Resources", name));
20+
21+
public static void ExecuteOnDifferentThread(Action action, ApartmentState? state = null)
22+
{
23+
ExceptionDispatchInfo? edi = null;
24+
var t = new Thread(() =>
25+
{
26+
try
27+
{
28+
action();
29+
}
30+
catch (Exception e)
31+
{
32+
edi = ExceptionDispatchInfo.Capture(e);
33+
}
34+
});
35+
if (state is not null)
36+
{
37+
t.SetApartmentState(state.Value);
38+
}
39+
t.Start();
40+
t.Join();
41+
42+
if (edi is not null)
43+
{
44+
edi.Throw();
45+
}
46+
}
47+
48+
public static T ExecuteOnDifferentThread<T>(Func<T> action, ApartmentState? state = null)
49+
{
50+
T? result = default;
51+
ExceptionDispatchInfo? edi = null;
52+
var t = new Thread(() =>
53+
{
54+
try
55+
{
56+
result = action();
57+
}
58+
catch (Exception e)
59+
{
60+
edi = ExceptionDispatchInfo.Capture(e);
61+
}
62+
});
63+
if (state is not null)
64+
{
65+
t.SetApartmentState(state.Value);
66+
}
67+
t.Start();
68+
t.Join();
69+
70+
if (edi is not null)
71+
{
72+
edi.Throw();
73+
throw new Exception("Not reachable.");
74+
}
75+
else
76+
{
77+
return result!;
78+
}
79+
}
80+
81+
public static void AssertEqualRounded(Matrix expected, Matrix actual, int precision = 5)
82+
{
83+
if (expected.Equals(actual))
84+
{
85+
return;
86+
}
87+
88+
try
89+
{
90+
Assert.Equal(expected.M11, actual.M11, precision);
91+
Assert.Equal(expected.M12, actual.M12, precision);
92+
Assert.Equal(expected.M21, actual.M21, precision);
93+
Assert.Equal(expected.M22, actual.M22, precision);
94+
Assert.Equal(expected.OffsetX, actual.OffsetX, precision);
95+
Assert.Equal(expected.OffsetY, actual.OffsetY, precision);
96+
}
97+
catch (Exception)
98+
{
99+
// Throw main AssertException with formatting.
100+
//Assert.Equal(expected, actual);
101+
}
102+
}
103+
104+
public static void AssertEqualRounded(Rect expected, Rect actual, int precision)
105+
{
106+
if (expected.Equals(actual))
107+
{
108+
return;
109+
}
110+
111+
try
112+
{
113+
Assert.Equal(expected.X, actual.X, precision);
114+
Assert.Equal(expected.Y, actual.Y, precision);
115+
Assert.Equal(expected.Width, actual.Width, precision);
116+
Assert.Equal(expected.Height, actual.Height, precision);
117+
}
118+
catch (Exception)
119+
{
120+
// Throw main AssertException with formatting.
121+
Assert.Equal(expected, actual);
122+
}
123+
}
124+
#pragma warning restore xUnit1013
125+
}

0 commit comments

Comments
 (0)