-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
484 additions
and
226 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/Microsoft.DotNet.Wpf/tests/UnitTests/WindowsBase.Tests/Helpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// 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.Collections.Specialized; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using System.Runtime.ExceptionServices; | ||
using System.Text; | ||
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 | ||
} |
4 changes: 4 additions & 0 deletions
4
...ts/WindowsBase.Tests/System/Collections/Specialized/CollectionChangedEventManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ests/UnitTests/WindowsBase.Tests/System/ComponentModel/CurrentChangedEventManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../tests/UnitTests/WindowsBase.Tests/System/ComponentModel/CurrentChangingEventArgsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...sts/UnitTests/WindowsBase.Tests/System/ComponentModel/CurrentChangingEventManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ts/UnitTests/WindowsBase.Tests/System/ComponentModel/DependencyPropertyDescriptorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tests/UnitTests/WindowsBase.Tests/System/ComponentModel/ErrorsChangedEventManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...tNet.Wpf/tests/UnitTests/WindowsBase.Tests/System/ComponentModel/GroupDescriptionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tNet.Wpf/tests/UnitTests/WindowsBase.Tests/System/ComponentModel/ItemPropertyInfoTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...sts/UnitTests/WindowsBase.Tests/System/ComponentModel/PropertyChangedEventManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...f/tests/UnitTests/WindowsBase.Tests/System/ComponentModel/PropertyFilterAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...tests/UnitTests/WindowsBase.Tests/System/ComponentModel/SortDescriptionCollectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...otNet.Wpf/tests/UnitTests/WindowsBase.Tests/System/ComponentModel/SortDescriptionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...Wpf/tests/UnitTests/WindowsBase.Tests/System/Diagnostics/PresentationTraceSourcesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...pf/tests/UnitTests/WindowsBase.Tests/System/IO/Packaging/EncryptedPackageEnvelopeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ts/UnitTests/WindowsBase.Tests/System/IO/Packaging/PackageDigitalSignatureManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...f/tests/UnitTests/WindowsBase.Tests/System/Security/RightsManagement/ContentGrantTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...pf/tests/UnitTests/WindowsBase.Tests/System/Security/RightsManagement/ContentUserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tests/UnitTests/WindowsBase.Tests/System/Security/RightsManagement/CryptoProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...s/WindowsBase.Tests/System/Security/RightsManagement/LocalizedNameDescriptionPairTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tests/UnitTests/WindowsBase.Tests/System/Security/RightsManagement/PublishLicenseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ests/WindowsBase.Tests/System/Security/RightsManagement/RightsManagementExceptionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ts/UnitTests/WindowsBase.Tests/System/Security/RightsManagement/SecureEnvironmentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...itTests/WindowsBase.Tests/System/Security/RightsManagement/UnsignedPublishLicenseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...Wpf/tests/UnitTests/WindowsBase.Tests/System/Security/RightsManagement/UseLicenseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tTests/WindowsBase.Tests/System/Windows/AttachedPropertyBrowsableForTypeAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...sBase.Tests/System/Windows/AttachedPropertyBrowsableWhenAttributePresentAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...Wpf/tests/UnitTests/WindowsBase.Tests/System/Windows/BaseCompatibilityPreferencesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ts/UnitTests/WindowsBase.Tests/System/Windows/Converters/Int32RectValueSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../tests/UnitTests/WindowsBase.Tests/System/Windows/Converters/PointValueSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...f/tests/UnitTests/WindowsBase.Tests/System/Windows/Converters/RectValueSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...f/tests/UnitTests/WindowsBase.Tests/System/Windows/Converters/SizeValueSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tests/UnitTests/WindowsBase.Tests/System/Windows/Converters/VectorValueSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...tNet.Wpf/tests/UnitTests/WindowsBase.Tests/System/Windows/Data/DataSourceProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.