Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Winforms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Private.Windows.P
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.Private.Windows.Polyfills", "src\Microsoft.Private.Windows.Polyfills\Microsoft.Private.Windows.Polyfills.shproj", "{799CC0C2-236B-4A76-8CE3-65C346182CC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Private.Windows.Core", "src\System.Private.Windows.Core\src\Microsoft.Private.Windows.Core.csproj", "{36A02BBB-B60B-5F23-6AF0-F41561A9275C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1082,6 +1084,22 @@ Global
{4A2BD741-482C-4BF7-8A2D-5535A770DB69}.Release|x64.Build.0 = Release|Any CPU
{4A2BD741-482C-4BF7-8A2D-5535A770DB69}.Release|x86.ActiveCfg = Release|Any CPU
{4A2BD741-482C-4BF7-8A2D-5535A770DB69}.Release|x86.Build.0 = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|arm64.ActiveCfg = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|arm64.Build.0 = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|x64.ActiveCfg = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|x64.Build.0 = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|x86.ActiveCfg = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Debug|x86.Build.0 = Debug|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|Any CPU.Build.0 = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|arm64.ActiveCfg = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|arm64.Build.0 = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|x64.ActiveCfg = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|x64.Build.0 = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|x86.ActiveCfg = Release|Any CPU
{36A02BBB-B60B-5F23-6AF0-F41561A9275C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1150,11 +1168,13 @@ Global
{7BFA3A16-A19A-4FCE-AE1E-D1187BD92D4C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{4A2BD741-482C-4BF7-8A2D-5535A770DB69} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
{799CC0C2-236B-4A76-8CE3-65C346182CC1} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7}
{36A02BBB-B60B-5F23-6AF0-F41561A9275C} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Microsoft.Private.Windows.Polyfills\Microsoft.Private.Windows.Polyfills.projitems*{36a02bbb-b60b-5f23-6af0-f41561a9275c}*SharedItemsImports = 5
src\Microsoft.Private.Windows.Polyfills\Microsoft.Private.Windows.Polyfills.projitems*{799cc0c2-236b-4a76-8ce3-65c346182cc1}*SharedItemsImports = 13
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public BinaryFormatterInClipboardDragDropScope(bool enable)
AppContextSwitchNames.ClipboardDragDropEnableUnsafeBinaryFormatterSerializationSwitchName,
() => AppContextSwitchScope.GetDefaultValueForSwitchInAssembly(
AppContextSwitchNames.ClipboardDragDropEnableUnsafeBinaryFormatterSerializationSwitchName,
#if NET
"System.Private.Windows.Core",
#else
"Microsoft.Private.Windows.Core",
#endif
"System.Private.Windows.CoreAppContextSwitches"),
enable);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Common/tests/TestUtilities/BinaryFormatterScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BinaryFormatterScope(bool enable)
// Prevent multiple BinaryFormatterScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(BinaryFormatterScope));
_switchScope = new(AppContextSwitchNames.EnableUnsafeBinaryFormatterSerialization, GetDefaultValue, enable);
_switchScope = new(AppContextSwitchNames.EnableUnsafeBinaryFormatterSerialization, () => false, enable);
}

public void Dispose()
Expand All @@ -31,6 +31,4 @@ public void Dispose()
Monitor.Exit(typeof(BinaryFormatterScope));
}
}

public static bool GetDefaultValue() => false;
}
5 changes: 4 additions & 1 deletion src/Common/tests/TestUtilities/BinarySerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

using System.Formats.Nrbf;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;

#if NET
using System.Runtime.CompilerServices;
#endif

namespace System;

public static class BinarySerialization
Expand Down
4 changes: 2 additions & 2 deletions src/Common/tests/TestUtilities/CommonTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public static TheoryData<char> GetCharTheoryData()
public static TheoryData<IntPtr> GetIntPtrTheoryData()
=> new()
{
-1,
(nint)(-1),
IntPtr.Zero,
1
(nint)1
};

public static TheoryData<Color> GetColorTheoryData()
Expand Down
2 changes: 2 additions & 0 deletions src/Common/tests/TestUtilities/ComparisonHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET
using System.Numerics;

namespace System;
Expand Down Expand Up @@ -110,3 +111,4 @@ public static bool EqualsFloating<T>(T x, T y, T variance)
static unsafe bool IsPositiveZero(T value) => T.IsZero(value) && T.IsPositive(value);
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing;
#if NET
using FluentAssertions.Collections;
#endif
using FluentAssertions.Execution;
using FluentAssertions.Numeric;
using FluentAssertions.Primitives;
Expand Down Expand Up @@ -43,6 +45,7 @@ public static AndConstraint<RectangleFAssertions> BeApproximately(
return new(parent);
}

#if NET
/// <summary>
/// Asserts that two <see cref="RectangleF"/> collections contain the same items in the same order
/// within the given <paramref name="precision"/>.
Expand All @@ -63,6 +66,7 @@ public static AndConstraint<GenericCollectionAssertions<RectangleF>> BeApproxima
&& ComparisonHelpers.EqualsFloating(expected.Height, actual.Height, precision),
because,
becauseArgs);
#endif

/// <summary>
/// Asserts a <see cref="PointF"/> value approximates another value as close as possible.
Expand All @@ -82,6 +86,7 @@ public static AndConstraint<PointFAssertions> BeApproximately(
return new AndConstraint<PointFAssertions>(parent);
}

#if NET
/// <summary>
/// Asserts that two <see cref="PointF"/> collections contain the same items in the same order
/// within the given <paramref name="precision"/>.
Expand All @@ -100,6 +105,7 @@ public static AndConstraint<GenericCollectionAssertions<PointF>> BeApproximately
&& ComparisonHelpers.EqualsFloating(expected.Y, actual.Y, precision),
because,
becauseArgs);
#endif

/// <summary>
/// Asserts a <see cref="Rectangle"/> is empty.
Expand Down
28 changes: 25 additions & 3 deletions src/Common/tests/TestUtilities/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace System;

internal static class ModuleInitializer
{
[ModuleInitializer]
#if NET
[Runtime.CompilerServices.ModuleInitializer]
#endif
[SuppressMessage("Usage", "CA2255:The 'ModuleInitializer' attribute should not be used in libraries", Justification = "Intentional use of module initializer to register trace listener.")]
internal static void Initialize()
{
Trace.Listeners.Clear();
Trace.Listeners.Add(ThrowingTraceListener.Instance);
}

#if NETFRAMEWORK
private static bool s_initialized;
private static readonly object s_lock = new object();

internal static void EnsureInitialized()
{
if (!s_initialized)
{
lock (s_lock)
{
if (s_initialized)
{
return;
}

Initialize();
s_initialized = true;
}
}
}
#endif
}
9 changes: 9 additions & 0 deletions src/Common/tests/TestUtilities/NoAssertContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public sealed class NoAssertContext : IDisposable
// We do, however need to lock around hooking/unhooking our custom listener to make sure that we
// are rerouting correctly if multiple threads are creating/disposing this class concurrently.

#if NET
private static readonly Lock s_lock = new();
#else
private static readonly object s_lock = new();
#endif

private static bool s_hooked;
private static bool s_hasDefaultListener;
private static bool s_hasThrowingListener;
Expand All @@ -31,6 +36,10 @@ public sealed class NoAssertContext : IDisposable

public NoAssertContext()
{
#if NETFRAMEWORK
ModuleInitializer.EnsureInitialized();
#endif

s_suppressedThreads.AddOrUpdate(Environment.CurrentManagedThreadId, 1, (key, oldValue) => oldValue + 1);

// Lock to make sure we are hooked properly if two threads come into the constructor/dispose at the same time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public NrbfSerializerInClipboardDragDropScope(bool enable)
AppContextSwitchNames.ClipboardDragDropEnableNrbfSerializationSwitchName,
() => AppContextSwitchScope.GetDefaultValueForSwitchInAssembly(
AppContextSwitchNames.ClipboardDragDropEnableNrbfSerializationSwitchName,
#if NET
"System.Private.Windows.Core",
#else
"Microsoft.Private.Windows.Core",
#endif
"System.Private.Windows.CoreAppContextSwitches"),
enable);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<TargetFrameworks>$(NetCurrent);net481</TargetFrameworks>
<AssemblyName>System.Private.Windows.Core.TestUtilities</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>System</RootNamespace>
Expand All @@ -11,6 +11,14 @@
<IsTestUtilityProject>true</IsTestUtilityProject>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net481'">
<!--
CA1822: The codebase contains a number of extension types where they reference instance state, but the analyzer
doesn't properly recognize this on .NET Framework.
-->
<NoWarn>$(NoWarn);CA1822</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AwesomeAssertions" />
<PackageReference Include="Moq" />
Expand All @@ -21,4 +29,32 @@
<PackageReference Include="System.Formats.Nrbf" />
</ItemGroup>

<!--
PolySharp related (source generated polyfills for .NET Framework)
-->
<PropertyGroup>
<PolySharpUsePublicAccessibilityForGeneratedTypes>false</PolySharpUsePublicAccessibilityForGeneratedTypes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!--
Global usings needed by the Polyfills shared project files.
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<Using Include="System.Diagnostics.CodeAnalysis" />
<Using Include="System.Runtime.CompilerServices" />
<!-- Needed for `dynamic` -->
<Reference Include="Microsoft.CSharp"/>
</ItemGroup>

<Import
Condition="'$(TargetFramework)' == 'net481'"
Project="..\..\..\Microsoft.Private.Windows.Polyfills\Microsoft.Private.Windows.Polyfills.projitems"
Label="Shared" />

</Project>
2 changes: 2 additions & 0 deletions src/Common/tests/TestUtilities/TempFile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET
using System.Runtime.CompilerServices;
#endif

namespace System.IO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET
using System.Numerics;

namespace Xunit;
Expand All @@ -15,3 +16,4 @@ public FloatingPointDataAttribute() : base(typeof(FloatingPointDataAttribute<TNu

public static ReadOnlyTheoryData TheoryData { get; } = new(TestData.GetFloatingPointData<TNumber>());
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET
using System.Numerics;

namespace System.XUnit;
Expand All @@ -20,3 +21,4 @@ public class FloatingPointToleranceComparerer<T> : IEqualityComparer<T>

public int GetHashCode([DisallowNull] T obj) => obj.GetHashCode();
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET
using System.Numerics;

namespace Xunit;
Expand All @@ -15,3 +16,4 @@ public IntegerDataAttribute() : base(typeof(IntegerDataAttribute<TNumber>)) { }

public static ReadOnlyTheoryData TheoryData { get; } = new(TestData.GetIntegerData<TNumber>());
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
#if NET
using System.Runtime.CompilerServices;
#endif

namespace Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET
using System.Numerics;

namespace Xunit;
Expand All @@ -15,3 +16,4 @@ public PositiveIntegerDataAttribute() : base(typeof(PositiveIntegerDataAttribute

public static ReadOnlyTheoryData TheoryData { get; } = new(TestData.GetPositiveIntegerData<TNumber>());
}
#endif
4 changes: 4 additions & 0 deletions src/Common/tests/TestUtilities/XUnit/TestData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET

using System.Collections.Immutable;
using System.Numerics;
namespace Xunit;
Expand Down Expand Up @@ -81,3 +83,5 @@ private static class PositiveIntegerData<T>
];
}
}

#endif
Loading