Skip to content

Commit 9480458

Browse files
committed
Add WindowsBase tests
1 parent 4120cfc commit 9480458

File tree

93 files changed

+48394
-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

+48394
-0
lines changed

Microsoft.Dotnet.Wpf.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{
249249
EndProject
250250
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Xaml.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Xaml.Tests\System.Xaml.Tests.csproj", "{B2F2A89C-55C9-41B1-A645-0948609BD8BE}"
251251
EndProject
252+
Project("{6FFF8BB3-74D1-4860-BEF1-5B307BCDBB95}") = "WindowsBase.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\WindowsBase.Tests\WindowsBase.Tests.csproj", "{A5DC575D-EC10-445B-94C1-98015F926FFA}"
253+
EndProject
252254
Global
253255
GlobalSection(SolutionConfigurationPlatforms) = preSolution
254256
Debug|Any CPU = Debug|Any CPU
@@ -1942,6 +1944,28 @@ Global
19421944
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x86.ActiveCfg = Release|Win32
19431945
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x86.Build.0 = Release|Win32
19441946
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x86.Deploy.0 = Release|Win32
1947+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.ActiveCfg = Debug|Win32
1948+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.Build.0 = Debug|Win32
1949+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|Any CPU.Deploy.0 = Debug|Win32
1950+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|ARM64.ActiveCfg = Debug|ARM64
1951+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|ARM64.Build.0 = Debug|ARM64
1952+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.ActiveCfg = Debug|x64
1953+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.Build.0 = Debug|x64
1954+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x64.Deploy.0 = Debug|x64
1955+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.ActiveCfg = Debug|Win32
1956+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.Build.0 = Debug|Win32
1957+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Debug|x86.Deploy.0 = Debug|Win32
1958+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.ActiveCfg = Release|Win32
1959+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.Build.0 = Release|Win32
1960+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|Any CPU.Deploy.0 = Release|Win32
1961+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|ARM64.ActiveCfg = Release|ARM64
1962+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|ARM64.Build.0 = Release|ARM64
1963+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.ActiveCfg = Release|x64
1964+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.Build.0 = Release|x64
1965+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x64.Deploy.0 = Release|x64
1966+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.ActiveCfg = Release|Win32
1967+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.Build.0 = Release|Win32
1968+
{A5DC575D-EC10-445B-94C1-98015F926FFA}.Release|x86.Deploy.0 = Release|Win32
19451969
EndGlobalSection
19461970
GlobalSection(SolutionProperties) = preSolution
19471971
HideSolutionNode = FALSE
@@ -2062,6 +2086,7 @@ Global
20622086
{34B64A4A-7C83-4F92-8C47-80E9FA10D660} = {C9ECC1A1-917F-43D3-B340-2035B4938507}
20632087
{A48B585E-6AB0-4F8D-8484-77F37CB44437} = {34B64A4A-7C83-4F92-8C47-80E9FA10D660}
20642088
{B2F2A89C-55C9-41B1-A645-0948609BD8BE} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
2089+
{A5DC575D-EC10-445B-94C1-98015F926FFA} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
20652090
EndGlobalSection
20662091
GlobalSection(ExtensibilityGlobals) = postSolution
20672092
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)