Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Test Utilities As Packable Nonshipping #12407

Merged
merged 7 commits into from
Nov 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion Winforms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesignSurfaceExt", "src\Sys
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Microsoft.VisualBasic.Forms.Tests", "src\Microsoft.VisualBasic.Forms\tests\UnitTests\Microsoft.VisualBasic.Forms.Tests.vbproj", "{FC75CB54-D8D0-4B41-9A4D-9F862F34A02D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Common.TestUtilities", "src\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj", "{05FD23CE-60AE-44A8-8DD6-1688F04BE385}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Windows.Core.TestUtilities", "src\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj", "{05FD23CE-60AE-44A8-8DD6-1688F04BE385}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Analyzers", "src\System.Windows.Forms.Analyzers\src\System.Windows.Forms.Analyzers.csproj", "{3596BDE6-B211-4BE7-810D-DC7A4315E296}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<!-- Reference and Source System.Windows.Forms -->
<ProjectReference Include="..\..\src\System.Windows.Forms\src\System.Windows.Forms.csproj" />

<!-- Reference and Source System.Windows.Forms.Primitives -->
<!-- Reference and Source System.Private.Windows.Core -->
<ProjectReference Include="..\..\src\System.Private.Windows.Core\src\System.Private.Windows.Core.csproj" />

<!-- Reference and Source System.Windows.Forms.Primitives -->
Expand Down
46 changes: 0 additions & 46 deletions src/Common/tests/TestUtilities/AppContextSwitchNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@ namespace System;

public static class AppContextSwitchNames
{
/// <summary>
/// The switch that controls whether AnchorLayoutV2 feature is enabled.
/// </summary>
public const string AnchorLayoutV2
= "System.Windows.Forms.AnchorLayoutV2";

/// <summary>
/// The switch that controls whether the parent font
/// (as set by <see cref="M:System.Windows.Forms.Application.SetDefaultFont(System.Drawing.Font)" />
/// or by the parent control or form's font) is applied to menus.
/// </summary>
public const string ApplyParentFontToMenus
= "System.Windows.Forms.ApplyParentFontToMenus";

/// <summary>
/// The switch that controls whether or not the DataGridView starts its UI row count at zero.
/// </summary>
public const string DataGridViewUIAStartRowCountAtZero
= "System.Windows.Forms.DataGridViewUIAStartRowCountAtZero";

/// <summary>
/// The switch that controls whether or not the <see cref="BinaryFormatter"/> is enabled.
/// </summary>
Expand All @@ -38,30 +18,4 @@ public const string EnableUnsafeBinaryFormatterSerialization
/// </summary>
public const string LocalAppContext_DisableCaching
= "TestSwitch.LocalAppContext.DisableCaching";

/// <summary>
/// The switch that controls whether UIA notifications are raised.
/// </summary>
public const string NoClientNotifications
= "Switch.System.Windows.Forms.AccessibleObject.NoClientNotifications";

/// <summary>
/// The switch that controls whether to scale the top level form min/max size for dpi.
/// </summary>
public const string ScaleTopLevelFormMinMaxSizeForDpi
= "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi";

/// <summary>
/// The switch that controls whether certificates are checked against the certificate authority revocation list.
/// If true, revoked certificates will not be accepted by WebRequests and WebClients as valid.
/// Otherwise, revoked certificates will be accepted as valid.
/// </summary>
public const string ServicePointManagerCheckCrl
= "System.Windows.Forms.ServicePointManagerCheckCrl";

/// <summary>
/// The switch that controls whether the TreeNodeCollection will insert nodes in the sorted order.
/// </summary>
public const string TreeNodeCollectionAddRangeRespectsSortOrder
= "System.Windows.Forms.ApplyParentFontToMenus";
}
26 changes: 18 additions & 8 deletions src/Common/tests/TestUtilities/BinarySerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace System;

public static class BinarySerialization
{
/// <summary>
/// Ensures the list of types marked as serializable under <paramref name="assemblyUnderTest"/> matches <paramref name="serializableTypes"/>.
/// If not, <see cref="NotSupportedException"/> is thrown.
/// </summary>
public static void EnsureSerializableAttribute(Assembly assemblyUnderTest, HashSet<string> serializableTypes)
{
foreach (Type type in assemblyUnderTest.GetTypes())
Expand Down Expand Up @@ -50,22 +54,24 @@ public static void EnsureSerializableAttribute(Assembly assemblyUnderTest, HashS
}
}

/// <summary>
/// Binary deserializes a base 64 string to <typeparamref name="T"/>. <paramref name="blob"/> is binary
/// deserialized with <see cref="BinaryFormatter"/> with <paramref name="assemblyStyle"/> taken into account.
/// </summary>
#pragma warning disable SYSLIB0050 // Type or member is obsolete
public static T EnsureDeserialize<T>(string blob)
public static T EnsureDeserialize<T>(string blob, FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
{
object @object = FromBase64String(blob);
object @object = FromBase64String(blob, assemblyStyle);
Assert.NotNull(@object);
return Assert.IsType<T>(@object);

static object FromBase64String(string base64String,
FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
static object FromBase64String(string base64String, FormatterAssemblyStyle assemblyStyle)
{
byte[] raw = Convert.FromBase64String(base64String);
return FromByteArray(raw, assemblyStyle);
}

static object FromByteArray(byte[] raw,
FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
static object FromByteArray(byte[] raw, FormatterAssemblyStyle assemblyStyle)
{
#pragma warning disable SYSLIB0011 // Type or member is obsolete
// cs/binary-formatter-without-binder
Expand All @@ -82,14 +88,18 @@ static object FromByteArray(byte[] raw,
}
}

/// <summary>
/// Returns a base 64 string of the binary serialized <paramref name="object"/>.
/// <paramref name="object"/> is binary serialized using <see cref="BinaryFormatter"/>
/// with <paramref name="assemblyStyle"/> taken into account.
/// </summary>
public static string ToBase64String(object @object,
FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
{
byte[] raw = ToByteArray(@object, assemblyStyle);
return Convert.ToBase64String(raw);

static byte[] ToByteArray(object obj,
FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
static byte[] ToByteArray(object obj, FormatterAssemblyStyle assemblyStyle)
{
#pragma warning disable SYSLIB0011 // Type or member is obsolete
// cs/binary-formatter-without-binder
Expand Down
2 changes: 1 addition & 1 deletion src/Common/tests/TestUtilities/CommonTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.ComponentModel.Design.Serialization;
using System.Drawing;

namespace System.Windows.Forms.TestUtilities;
namespace System.Private.Windows.Core.TestUtilities;

public static class CommonTestHelper
{
Expand Down
3 changes: 3 additions & 0 deletions src/Common/tests/TestUtilities/FileCleanupTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace System;

/// <summary>
/// Creates a test directory path and cleans it up when test class finishes execution.
/// </summary>
public abstract class FileCleanupTestBase : IDisposable
{
private string? _testDirectory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>System.Windows.Forms.Common.TestUtilities</AssemblyName>
<AssemblyName>System.Private.Windows.Core.TestUtilities</AssemblyName>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to rename the folder in a separate PR to preserve history?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this assembly lives under the test folder. I was not planning to rename it as I think it should still be there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the common folder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I think the folder name is still applicable, but I'm open to renaming.

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>System</RootNamespace>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<IsShipping>false</IsShipping>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Common/tests/TestUtilities/TempFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
namespace System.IO;

/// <summary>
/// Represents a temporary file. Creating an instance creates a file at the specified path,
/// and disposing the instance deletes the file.
/// Represents a temporary file. Creating an instance creates a file at the specified path,
/// and disposing the instance deletes the file.
/// </summary>
/// <remarks>
/// <para>
Expand Down
6 changes: 5 additions & 1 deletion src/Common/tests/TestUtilities/TestIncludeType.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Windows.Forms.TestUtilities;
namespace System.Private.Windows.Core.TestUtilities;

/// <summary>
/// Specifies what type of test data to include in the <see cref="TheoryData"/>. This is
/// used in <see cref="CommonMemberDataAttribute"/>
/// </summary>
[Flags]
public enum TestIncludeType
{
Expand Down
3 changes: 3 additions & 0 deletions src/Common/tests/TestUtilities/ThreadCultureChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace System;

/// <summary>
/// Facilitates temporarily changing the <see cref="CultureInfo.CurrentCulture"/> and <see cref="CultureInfo.CurrentUICulture"/>.
/// </summary>
public sealed class ThreadCultureChange : IDisposable
{
private readonly CultureInfo _origCulture = CultureInfo.CurrentCulture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\System.Windows.Forms.Analyzers.CodeFixes.CSharp\System.Windows.Forms.Analyzers.CodeFixes.CSharp.csproj" />
<ProjectReference Include="..\..\..\System.Windows.Forms.Analyzers\src\System.Windows.Forms.Analyzers.csproj" />
<ProjectReference Include="..\..\..\System.Windows.Forms.Analyzers\tests\UnitTests\System.Windows.Forms.Analyzers.Tests.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\..\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\..\System.Windows.Forms.Analyzers.CodeFixes.VisualBasic\System.Windows.Forms.Analyzers.CodeFixes.VisualBasic.vbproj" />
<ProjectReference Include="..\..\..\..\System.Windows.Forms.Analyzers\src\System.Windows.Forms.Analyzers.csproj" />
<ProjectReference Include="..\..\..\..\System.Windows.Forms.Analyzers\tests\UnitTests\System.Windows.Forms.Analyzers.Tests.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj" />
<ProjectReference Include="..\..\src\System.Windows.Forms.Analyzers.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\System.Windows.Forms\src\System.Windows.Forms.csproj" />
<ProjectReference Include="..\..\src\System.Windows.Forms.Primitives.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\..\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj" />
<ProjectReference Include="..\..\..\..\System.Design\src\System.Design.Facade.csproj" />
<ProjectReference Include="..\..\..\..\System.Drawing.Design\src\System.Drawing.Design.Facade.csproj" />
<ProjectReference Include="..\..\..\..\System.Windows.Forms.Primitives\src\System.Windows.Forms.Primitives.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AnchorLayoutV2Scope(bool enable)
// Prevent multiple AnchorLayoutV2Scope instances from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(AnchorLayoutV2Scope));
_switchScope = new(AppContextSwitchNames.AnchorLayoutV2, enable);
_switchScope = new(WinFormsAppContextSwitchNames.AnchorLayoutV2, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ApplyParentFontToMenusScope(bool enable)
// Prevent multiple ApplyParentFontToMenusScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(ApplyParentFontToMenusScope));
_switchScope = new(AppContextSwitchNames.ApplyParentFontToMenus, enable);
_switchScope = new(WinFormsAppContextSwitchNames.ApplyParentFontToMenus, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DataGridViewUIAStartRowCountAtZeroScope(bool enable)
// Prevent multiple BinaryFormatterScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(DataGridViewUIAStartRowCountAtZeroScope));
_switchScope = new(AppContextSwitchNames.DataGridViewUIAStartRowCountAtZero, enable);
_switchScope = new(WinFormsAppContextSwitchNames.DataGridViewUIAStartRowCountAtZero, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public NoClientNotificationsScope(bool enable)
// Prevent multiple NoClientNotificationsScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(NoClientNotificationsScope));
_switchScope = new(AppContextSwitchNames.NoClientNotifications, enable);
_switchScope = new(WinFormsAppContextSwitchNames.NoClientNotifications, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ScaleTopLevelFormMinMaxSizeForDpiScope(bool enable)
// Prevent multiple ScaleTopLevelFormMinMaxSizeForDpi from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(ScaleTopLevelFormMinMaxSizeForDpiScope));
_switchScope = new(AppContextSwitchNames.ScaleTopLevelFormMinMaxSizeForDpi, enable);
_switchScope = new(WinFormsAppContextSwitchNames.ScaleTopLevelFormMinMaxSizeForDpi, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ServicePointManagerCheckCrlScope(bool enable)
// Prevent multiple ServicePointManagerCheckCrlScope instances from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(ServicePointManagerCheckCrlScope));
_switchScope = new(AppContextSwitchNames.ServicePointManagerCheckCrl, enable);
_switchScope = new(WinFormsAppContextSwitchNames.ServicePointManagerCheckCrl, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TreeNodeCollectionAddRangeRespectsSortOrderScope(bool enable)
// Prevent multiple TreeNodeCollectionAddRangeRespectsSortOrderScopes from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(TreeNodeCollectionAddRangeRespectsSortOrderScope));
_switchScope = new(AppContextSwitchNames.TreeNodeCollectionAddRangeRespectsSortOrder, enable);
_switchScope = new(WinFormsAppContextSwitchNames.TreeNodeCollectionAddRangeRespectsSortOrder, enable);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System;

public static class WinFormsAppContextSwitchNames
{
/// <summary>
/// The switch that controls whether AnchorLayoutV2 feature is enabled.
/// </summary>
public const string AnchorLayoutV2
= "System.Windows.Forms.AnchorLayoutV2";

/// <summary>
/// The switch that controls whether the parent font
/// (as set by <see cref="M:System.Windows.Forms.Application.SetDefaultFont(System.Drawing.Font)" />
/// or by the parent control or form's font) is applied to menus.
/// </summary>
public const string ApplyParentFontToMenus
= "System.Windows.Forms.ApplyParentFontToMenus";

/// <summary>
/// The switch that controls whether or not the DataGridView starts its UI row count at zero.
/// </summary>
public const string DataGridViewUIAStartRowCountAtZero
= "System.Windows.Forms.DataGridViewUIAStartRowCountAtZero";

/// <summary>
/// The switch that controls whether UIA notifications are raised.
/// </summary>
public const string NoClientNotifications
= "Switch.System.Windows.Forms.AccessibleObject.NoClientNotifications";

/// <summary>
/// The switch that controls whether to scale the top level form min/max size for dpi.
/// </summary>
public const string ScaleTopLevelFormMinMaxSizeForDpi
= "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi";

/// <summary>
/// The switch that controls whether certificates are checked against the certificate authority revocation list.
/// If true, revoked certificates will not be accepted by WebRequests and WebClients as valid.
/// Otherwise, revoked certificates will be accepted as valid.
/// </summary>
public const string ServicePointManagerCheckCrl
= "System.Windows.Forms.ServicePointManagerCheckCrl";

/// <summary>
/// The switch that controls whether the TreeNodeCollection will insert nodes in the sorted order.
/// </summary>
public const string TreeNodeCollectionAddRangeRespectsSortOrder
= "System.Windows.Forms.ApplyParentFontToMenus";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing;
using System.Windows.Forms.TestUtilities;

namespace System.Windows.Forms.Tests;

Expand Down
1 change: 1 addition & 0 deletions src/System.Windows.Forms/tests/UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using System.Diagnostics;
global using System.Windows.Forms;
global using System.Private.Windows.Core;
global using System.Private.Windows.Core.TestUtilities;
global using Windows.Win32;
global using Windows.Win32.Foundation;
global using Windows.Win32.Graphics.Gdi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Windows.Forms.TestUtilities;

namespace System.Windows.Forms.Tests;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms.TestUtilities;

namespace System.Windows.Forms.Tests;

Expand Down
Loading