From afac7b519e7abf7058ba5b9d426c583aa83d2162 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:03:18 +1100 Subject: [PATCH 01/16] Create infra --- Winforms.sln | 18 +- .../src/ITestAccessor.cs | 56 ----- .../src/TestAccessor.cs | 211 ------------------ .../src/TestAccessors.cs | 57 ----- ...stem.Windows.Forms.Primitives.Tests.csproj | 25 --- .../Interop/ComCtl32/LVITEMWTests.cs | 0 .../Interop/ComCtl32/MCGRIDINFOTests.cs | 0 .../Interop/Comdlg32/PRINTDLGWTests.cs | 0 .../Interop/Mso/IMsoComponentManagerTests.cs | 0 .../Interop/NtDll/RtlGetVersionTests.cs | 0 .../Interop/Ole32/IPictureTests.cs | 0 .../Interop/Oleaut32/IDispatchTests.cs | 0 .../Interop/Oleaut32/ITypeInfoTests.cs | 0 .../Interop/Richedit/CHARFORMATWTests.cs | 0 .../Interop/Richedit/EDITSTREAMTests.cs | 0 .../Interop/User32/GetWindowTextTests.cs | 0 .../Interop/User32/LOGFONTWTests.cs | 0 .../Interop/User32/SysInfoTests.cs | 0 ...stem.Windows.Forms.Primitives.Tests.csproj | 19 ++ .../tests/Utilities}/ArchitectureDetection.cs | 0 .../Utilities/Extensions}/AssertExtensions.cs | 0 .../Utilities/Extensions}/TheoryExtensions.cs | 0 .../tests/Utilities}/NoAssertContext.cs | 0 ...dows.Forms.Primitives.TestUtilities.csproj | 17 ++ .../tests/Utilities}/AdminHelpers.cs | 0 .../tests/Utilities}/BinarySerialization.cs | 0 .../Utilities}/CommonMemberDataAttribute.cs | 0 .../tests/Utilities}/CommonTestHelper.cs | 0 .../tests/Utilities}/GdiHelper.cs | 0 .../Utilities}/PlatformDetection.Windows.cs | 0 .../tests/Utilities}/PlatformDetection.cs | 0 .../System.Windows.Forms.TestUtilities.csproj | 12 + .../tests/Utilities}/TempFile.cs | 0 .../Utilities}/ThreadExceptionFixture.cs | 0 .../tests/Utilities}/WindowClass.cs | 0 35 files changed, 64 insertions(+), 351 deletions(-) delete mode 100644 src/Common/tests/InternalUtilitiesForTests/src/ITestAccessor.cs delete mode 100644 src/Common/tests/InternalUtilitiesForTests/src/TestAccessor.cs delete mode 100644 src/Common/tests/InternalUtilitiesForTests/src/TestAccessors.cs delete mode 100644 src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/ComCtl32/LVITEMWTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/ComCtl32/MCGRIDINFOTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Comdlg32/PRINTDLGWTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Mso/IMsoComponentManagerTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/NtDll/RtlGetVersionTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Ole32/IPictureTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Oleaut32/IDispatchTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Oleaut32/ITypeInfoTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Richedit/CHARFORMATWTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/Richedit/EDITSTREAMTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/User32/GetWindowTextTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/User32/LOGFONTWTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/User32/SysInfoTests.cs (100%) create mode 100644 src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms.Primitives/tests/Utilities}/ArchitectureDetection.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms.Primitives/tests/Utilities/Extensions}/AssertExtensions.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms.Primitives/tests/Utilities/Extensions}/TheoryExtensions.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms.Primitives/tests/Utilities}/NoAssertContext.cs (100%) create mode 100644 src/System.Windows.Forms.Primitives/tests/Utilities/System.Windows.Forms.Primitives.TestUtilities.csproj rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms/tests/Utilities}/AdminHelpers.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms/tests/Utilities}/BinarySerialization.cs (100%) rename src/{Common/tests => System.Windows.Forms/tests/Utilities}/CommonMemberDataAttribute.cs (100%) rename src/{Common/tests => System.Windows.Forms/tests/Utilities}/CommonTestHelper.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms/tests/Utilities}/GdiHelper.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms/tests/Utilities}/PlatformDetection.Windows.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms/tests/Utilities}/PlatformDetection.cs (100%) create mode 100644 src/System.Windows.Forms/tests/Utilities/System.Windows.Forms.TestUtilities.csproj rename src/{Common/tests => System.Windows.Forms/tests/Utilities}/TempFile.cs (100%) rename src/{Common/tests => System.Windows.Forms/tests/Utilities}/ThreadExceptionFixture.cs (100%) rename src/{Common/tests/InternalUtilitiesForTests/src => System.Windows.Forms/tests/Utilities}/WindowClass.cs (100%) diff --git a/Winforms.sln b/Winforms.sln index 03304b28b9a..bb00e078623 100644 --- a/Winforms.sln +++ b/Winforms.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28627.84 @@ -117,7 +117,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiLabelTests", "src\Syste EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Primitives", "src\System.Windows.Forms.Primitives\src\System.Windows.Forms.Primitives.csproj", "{90B27178-F535-43F7-886E-0AB75203F246}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Primitives.Tests", "src\System.Windows.Forms.Primitives\tests\System.Windows.Forms.Primitives.Tests.csproj", "{9BFDE7F2-C8F3-40D6-9A16-8DCD1A37E900}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Primitives.Tests", "src\System.Windows.Forms.Primitives\tests\UnitTests\System.Windows.Forms.Primitives.Tests.csproj", "{9BFDE7F2-C8F3-40D6-9A16-8DCD1A37E900}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4AA2764C-B013-40B5-9E5B-9459EF976C8B}" ProjectSection(SolutionItems) = preProject @@ -130,6 +130,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiMonthCalendarTests", "s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiTestsHelper", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauiTestsHelper\MauiTestsHelper.csproj", "{44BB1092-1844-4EAF-8DF5-338DE4C3149A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Primitives.TestUtilities", "src\System.Windows.Forms.Primitives\tests\Utilities\System.Windows.Forms.Primitives.TestUtilities.csproj", "{73B0857A-966B-4E7D-8A83-FECFE0281AB9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.TestUtilities", "src\System.Windows.Forms\tests\Utilities\System.Windows.Forms.TestUtilities.csproj", "{86418F0B-39DC-4B5A-8145-6D607E6150AC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -260,6 +264,14 @@ Global {44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Debug|Any CPU.Build.0 = Debug|Any CPU {44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Release|Any CPU.ActiveCfg = Release|Any CPU {44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Release|Any CPU.Build.0 = Release|Any CPU + {73B0857A-966B-4E7D-8A83-FECFE0281AB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {73B0857A-966B-4E7D-8A83-FECFE0281AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {73B0857A-966B-4E7D-8A83-FECFE0281AB9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {73B0857A-966B-4E7D-8A83-FECFE0281AB9}.Release|Any CPU.Build.0 = Release|Any CPU + {86418F0B-39DC-4B5A-8145-6D607E6150AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86418F0B-39DC-4B5A-8145-6D607E6150AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86418F0B-39DC-4B5A-8145-6D607E6150AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86418F0B-39DC-4B5A-8145-6D607E6150AC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -301,6 +313,8 @@ Global {E0681991-228A-420E-85D5-A9E796F0AAE0} = {434C00C3-E498-4BA7-9764-9F0FC8CFE457} {9DDC6936-9197-4C09-8640-AF0BE4918700} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F} {44BB1092-1844-4EAF-8DF5-338DE4C3149A} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F} + {73B0857A-966B-4E7D-8A83-FECFE0281AB9} = {DF68A171-D27B-4E6A-8A7E-63A651622355} + {86418F0B-39DC-4B5A-8145-6D607E6150AC} = {DF68A171-D27B-4E6A-8A7E-63A651622355} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136} diff --git a/src/Common/tests/InternalUtilitiesForTests/src/ITestAccessor.cs b/src/Common/tests/InternalUtilitiesForTests/src/ITestAccessor.cs deleted file mode 100644 index 3c632a07d79..00000000000 --- a/src/Common/tests/InternalUtilitiesForTests/src/ITestAccessor.cs +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -namespace System -{ - /// - /// Interface for accessing internals from tests. - /// - /// - /// A non generic representation of the acessor functionality is needed to - /// allow dynamically creating arbitrary from - /// helper methods. - /// - public interface ITestAccessor - { - /// - /// Gets a dynamic accessor to internals on the test object. - /// - /// - /// This does not work for ref structs as they are not yet accessible via reflection. - /// See https://github.com/dotnet/runtime/issues/10057. - /// - dynamic Dynamic { get; } - - /// - /// Creates a delegate for the given non-public method. - /// - /// - /// The method name. If null, uses the name of the delegate for the method. - /// - /// - /// This provides a way to access methods that take ref structs. - /// - /// - /// path); - /// - /// public int InternalGetDirectoryNameOffset(ReadOnlySpan path) - /// { - /// var accessor = typeof(System.IO.Path).TestAccessor(); - /// return accessor.CreateDelegate()(@"C:\Foo"); - /// } - /// - /// // Without ref structs you can just use Func/Action - /// var accessor = typeof(Color).TestAccessor(); - /// bool result = accessor.CreateDelegate>("IsKnownColorSystem")(KnownColor.Window); - /// ]]> - /// - TDelegate CreateDelegate(string methodName = null) - where TDelegate : Delegate; - } -} diff --git a/src/Common/tests/InternalUtilitiesForTests/src/TestAccessor.cs b/src/Common/tests/InternalUtilitiesForTests/src/TestAccessor.cs deleted file mode 100644 index b99e77a4b62..00000000000 --- a/src/Common/tests/InternalUtilitiesForTests/src/TestAccessor.cs +++ /dev/null @@ -1,211 +0,0 @@ -// 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.Dynamic; -using System.Linq; -using System.Reflection; - -namespace System -{ - /// - /// Internals (including privates) access wrapper for tests. - /// - /// The type of the class being accessed. - /// - /// Does not allow access to public members- use the object directly. - /// - /// One should strive to *not* access internal state where otherwise avoidable. - /// Ask yourself if you can test the contract of the object in question - /// *without* manipulating internals directly. Often you can. - /// - /// Where internals access is more useful are testing building blocks of more - /// complicated objects, such as internal helper methods or classes. - /// - /// This can be used to access private/internal objects as well via - /// - /// - /// This class can also be derived from to create a strongly typed wrapper - /// that can then be associated via an extension method for the given type - /// to provide consistent discovery and access. - /// - /// - /// { - /// public TestAccessor(Guid instance) : base(instance) {} - /// - /// public int A => Dynamic._a; - /// } - /// - /// public static partial class TestAccessors - /// { - /// public static GuidTestAccessor TestAccessor(this Guid guid) - /// => new GuidTestAccessor(guid); - /// } - /// ]]> - /// - public class TestAccessor : ITestAccessor - { - private static readonly Type s_type = typeof(T); - protected readonly T _instance; - private readonly DynamicWrapper _dynamicWrapper; - - /// The type instance, can be null for statics. - public TestAccessor(T instance) - { - _instance = instance; - _dynamicWrapper = new DynamicWrapper(_instance); - } - - /// - public TDelegate CreateDelegate(string methodName = null) - where TDelegate : Delegate - { - Type type = typeof(TDelegate); - Type[] types = type.GetMethod("Invoke").GetParameters().Select(pi => pi.ParameterType).ToArray(); - - // To make it easier to write a class wrapper with a number of delegates, - // we'll take the name from the delegate itself when unspecified. - if (methodName == null) - methodName = type.Name; - - MethodInfo methodInfo = s_type.GetMethod( - methodName, - BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, - binder: null, - types, - modifiers: null); - - if (methodInfo == null) - throw new ArgumentException($"Could not find non public method {methodName}."); - - return (TDelegate)methodInfo.CreateDelegate(type, methodInfo.IsStatic ? (object)null : _instance); - } - - /// - public dynamic Dynamic => _dynamicWrapper; - - private class DynamicWrapper : DynamicObject - { - private readonly object _instance; - - public DynamicWrapper(object instance) - => _instance = instance; - - public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) - { - result = null; - - MethodInfo methodInfo = null; - Type type = s_type; - - do - { - try - { - methodInfo = type.GetMethod( - binder.Name, - BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); - } - catch (AmbiguousMatchException) - { - // More than one match for the name, specify the arguments - methodInfo = type.GetMethod( - binder.Name, - BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, - binder: null, - args.Select(a => a.GetType()).ToArray(), - modifiers: null); - } - - if (methodInfo != null || type == typeof(object)) - { - // Found something, or already at the top of the type heirarchy - break; - } - - // Walk up the heirarchy - type = type.BaseType; - } while (true); - - if (methodInfo == null) - return false; - - result = methodInfo.Invoke(_instance, args); - return true; - } - - public override bool TrySetMember(SetMemberBinder binder, object value) - { - MemberInfo info = GetFieldOrPropertyInfo(binder.Name); - if (info == null) - return false; - - SetValue(info, value); - return true; - } - - public override bool TryGetMember(GetMemberBinder binder, out object result) - { - result = null; - - MemberInfo info = GetFieldOrPropertyInfo(binder.Name); - if (info == null) - return false; - - result = GetValue(info); - return true; - } - - private MemberInfo GetFieldOrPropertyInfo(string memberName) - { - Type type = s_type; - MemberInfo info; - - do - { - info = (MemberInfo)type.GetField( - memberName, - BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic) - ?? type.GetProperty( - memberName, - BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic); - - if (info != null || type == typeof(object)) - { - // Found something, or already at the top of the type heirarchy - break; - } - - // Walk up the type heirarchy - type = s_type.BaseType; - } while (true); - - return info; - } - - private object GetValue(MemberInfo memberInfo) - => memberInfo switch - { - FieldInfo fieldInfo => fieldInfo.GetValue(_instance), - PropertyInfo propertyInfo => propertyInfo.GetValue(_instance), - _ => throw new InvalidOperationException() - }; - - private void SetValue(MemberInfo memberInfo, object value) - { - switch (memberInfo) - { - case FieldInfo fieldInfo: - fieldInfo.SetValue(_instance, value); - break; - case PropertyInfo propertyInfo: - propertyInfo.SetValue(_instance, value); - break; - default: - throw new InvalidOperationException(); - } - } - } - } -} diff --git a/src/Common/tests/InternalUtilitiesForTests/src/TestAccessors.cs b/src/Common/tests/InternalUtilitiesForTests/src/TestAccessors.cs deleted file mode 100644 index c3e4068847c..00000000000 --- a/src/Common/tests/InternalUtilitiesForTests/src/TestAccessors.cs +++ /dev/null @@ -1,57 +0,0 @@ -// 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.Windows.Forms; - -namespace System -{ - /// - /// Extension methods for associating internals test accessors with - /// types being tested. - /// - /// - /// In the System namespace for implicit discovery. - /// - public static class TestAccessors - { - // Need to pass a null parameter when constructing a static instance - // of TestAccessor. As this is pretty common and never changes, caching - // the array here. - private static object[] s_nullObjectParam = { null }; - - /// - /// Extension that creates a generic internals test accessor for a - /// given instance or Type class (if only accessing statics). - /// - /// - /// Instance or Type class (if only accessing statics). - /// - /// - /// - /// - public static ITestAccessor TestAccessor(this object instanceOrType) - { - if (instanceOrType is Type type) - { - return (ITestAccessor)Activator.CreateInstance( - typeof(TestAccessor<>).MakeGenericType(type), - s_nullObjectParam); - } - else - { - return (ITestAccessor)Activator.CreateInstance( - typeof(TestAccessor<>).MakeGenericType(instanceOrType.GetType()), - instanceOrType); - } - } - } -} diff --git a/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj b/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj deleted file mode 100644 index 0ae2e2c762d..00000000000 --- a/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - System.Windows.Forms.Primitives.Tests - true - - - - - - - - - - - - - - - - - - - - diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/LVITEMWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/LVITEMWTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/LVITEMWTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/LVITEMWTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/MCGRIDINFOTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/MCGRIDINFOTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Comdlg32/PRINTDLGWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Comdlg32/PRINTDLGWTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Mso/IMsoComponentManagerTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mso/IMsoComponentManagerTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Mso/IMsoComponentManagerTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mso/IMsoComponentManagerTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/NtDll/RtlGetVersionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/NtDll/RtlGetVersionTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/NtDll/RtlGetVersionTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/NtDll/RtlGetVersionTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Ole32/IPictureTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Ole32/IPictureTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Oleaut32/IDispatchTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Oleaut32/IDispatchTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Oleaut32/ITypeInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Oleaut32/ITypeInfoTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Richedit/CHARFORMATWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/CHARFORMATWTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Richedit/CHARFORMATWTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/CHARFORMATWTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Richedit/EDITSTREAMTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/Richedit/EDITSTREAMTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/User32/GetWindowTextTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/User32/GetWindowTextTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/User32/LOGFONTWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/LOGFONTWTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/User32/LOGFONTWTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/LOGFONTWTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/User32/SysInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/SysInfoTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/User32/SysInfoTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/SysInfoTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj new file mode 100644 index 00000000000..c83401cbca5 --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj @@ -0,0 +1,19 @@ + + + + System.Windows.Forms.Primitives.Tests + true + + + + + + + + + + + + + + diff --git a/src/Common/tests/InternalUtilitiesForTests/src/ArchitectureDetection.cs b/src/System.Windows.Forms.Primitives/tests/Utilities/ArchitectureDetection.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/ArchitectureDetection.cs rename to src/System.Windows.Forms.Primitives/tests/Utilities/ArchitectureDetection.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/AssertExtensions.cs b/src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/AssertExtensions.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/AssertExtensions.cs rename to src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/AssertExtensions.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/TheoryExtensions.cs b/src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/TheoryExtensions.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/TheoryExtensions.cs rename to src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/TheoryExtensions.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/NoAssertContext.cs b/src/System.Windows.Forms.Primitives/tests/Utilities/NoAssertContext.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/NoAssertContext.cs rename to src/System.Windows.Forms.Primitives/tests/Utilities/NoAssertContext.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Utilities/System.Windows.Forms.Primitives.TestUtilities.csproj b/src/System.Windows.Forms.Primitives/tests/Utilities/System.Windows.Forms.Primitives.TestUtilities.csproj new file mode 100644 index 00000000000..c796dd8302f --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/Utilities/System.Windows.Forms.Primitives.TestUtilities.csproj @@ -0,0 +1,17 @@ + + + System.Windows.Forms.Primitives.TestUtilities + true + System + + + + + + + + + + + + diff --git a/src/Common/tests/InternalUtilitiesForTests/src/AdminHelpers.cs b/src/System.Windows.Forms/tests/Utilities/AdminHelpers.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/AdminHelpers.cs rename to src/System.Windows.Forms/tests/Utilities/AdminHelpers.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/BinarySerialization.cs b/src/System.Windows.Forms/tests/Utilities/BinarySerialization.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/BinarySerialization.cs rename to src/System.Windows.Forms/tests/Utilities/BinarySerialization.cs diff --git a/src/Common/tests/CommonMemberDataAttribute.cs b/src/System.Windows.Forms/tests/Utilities/CommonMemberDataAttribute.cs similarity index 100% rename from src/Common/tests/CommonMemberDataAttribute.cs rename to src/System.Windows.Forms/tests/Utilities/CommonMemberDataAttribute.cs diff --git a/src/Common/tests/CommonTestHelper.cs b/src/System.Windows.Forms/tests/Utilities/CommonTestHelper.cs similarity index 100% rename from src/Common/tests/CommonTestHelper.cs rename to src/System.Windows.Forms/tests/Utilities/CommonTestHelper.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/GdiHelper.cs b/src/System.Windows.Forms/tests/Utilities/GdiHelper.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/GdiHelper.cs rename to src/System.Windows.Forms/tests/Utilities/GdiHelper.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/PlatformDetection.Windows.cs b/src/System.Windows.Forms/tests/Utilities/PlatformDetection.Windows.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/PlatformDetection.Windows.cs rename to src/System.Windows.Forms/tests/Utilities/PlatformDetection.Windows.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/PlatformDetection.cs b/src/System.Windows.Forms/tests/Utilities/PlatformDetection.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/PlatformDetection.cs rename to src/System.Windows.Forms/tests/Utilities/PlatformDetection.cs diff --git a/src/System.Windows.Forms/tests/Utilities/System.Windows.Forms.TestUtilities.csproj b/src/System.Windows.Forms/tests/Utilities/System.Windows.Forms.TestUtilities.csproj new file mode 100644 index 00000000000..56ed147a54a --- /dev/null +++ b/src/System.Windows.Forms/tests/Utilities/System.Windows.Forms.TestUtilities.csproj @@ -0,0 +1,12 @@ + + + System.Windows.Forms.TestUtilities + true + System + + + + + + + diff --git a/src/Common/tests/TempFile.cs b/src/System.Windows.Forms/tests/Utilities/TempFile.cs similarity index 100% rename from src/Common/tests/TempFile.cs rename to src/System.Windows.Forms/tests/Utilities/TempFile.cs diff --git a/src/Common/tests/ThreadExceptionFixture.cs b/src/System.Windows.Forms/tests/Utilities/ThreadExceptionFixture.cs similarity index 100% rename from src/Common/tests/ThreadExceptionFixture.cs rename to src/System.Windows.Forms/tests/Utilities/ThreadExceptionFixture.cs diff --git a/src/Common/tests/InternalUtilitiesForTests/src/WindowClass.cs b/src/System.Windows.Forms/tests/Utilities/WindowClass.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/src/WindowClass.cs rename to src/System.Windows.Forms/tests/Utilities/WindowClass.cs From 696503876c45e36b365408a000c4f950dfc88cb8 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:08:21 +1100 Subject: [PATCH 02/16] System.Windows.Forms.Primitives.Tests compile, some tests commented out --- Winforms.sln | 4 +- .../ArchitectureDetection.cs | 0 .../Extensions/AssertExtensions.cs | 0 .../Extensions/TheoryExtensions.cs | 0 .../tests/TestUtilities/ITestAccessor.cs | 56 +++++ .../NoAssertContext.cs | 0 ...dows.Forms.Primitives.TestUtilities.csproj | 0 .../tests/TestUtilities/TestAccessor.cs | 211 ++++++++++++++++++ .../tests/TestUtilities/TestAccessors.cs | 57 +++++ .../TASKDIALOGCONFIGIconUnionTests.cs | 0 .../Interop/ComCtl32/TASKDIALOGCONFIGTests.cs | 0 .../ComCtl32/TASKDIALOG_BUTTONTests.cs | 0 .../Forms/FileDialogCustomPlaceTests.cs | 0 .../FileDialogCustomPlacesCollectionTests.cs | 0 .../AdminHelpers.cs | 0 .../BinarySerialization.cs | 0 .../CommonMemberDataAttribute.cs | 0 .../CommonTestHelper.cs | 0 .../{Utilities => TestUtilities}/GdiHelper.cs | 0 .../PlatformDetection.Windows.cs | 0 .../PlatformDetection.cs | 0 .../System.Windows.Forms.TestUtilities.csproj | 0 .../{Utilities => TestUtilities}/TempFile.cs | 0 .../ThreadExceptionFixture.cs | 0 .../WindowClass.cs | 0 25 files changed, 326 insertions(+), 2 deletions(-) rename src/System.Windows.Forms.Primitives/tests/{Utilities => TestUtilities}/ArchitectureDetection.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{Utilities => TestUtilities}/Extensions/AssertExtensions.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{Utilities => TestUtilities}/Extensions/TheoryExtensions.cs (100%) create mode 100644 src/System.Windows.Forms.Primitives/tests/TestUtilities/ITestAccessor.cs rename src/System.Windows.Forms.Primitives/tests/{Utilities => TestUtilities}/NoAssertContext.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{Utilities => TestUtilities}/System.Windows.Forms.Primitives.TestUtilities.csproj (100%) create mode 100644 src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessor.cs create mode 100644 src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessors.cs rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/System/Windows/Forms/FileDialogCustomPlaceTests.cs (100%) rename src/System.Windows.Forms.Primitives/tests/{ => UnitTests}/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/AdminHelpers.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/BinarySerialization.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/CommonMemberDataAttribute.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/CommonTestHelper.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/GdiHelper.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/PlatformDetection.Windows.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/PlatformDetection.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/System.Windows.Forms.TestUtilities.csproj (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/TempFile.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/ThreadExceptionFixture.cs (100%) rename src/System.Windows.Forms/tests/{Utilities => TestUtilities}/WindowClass.cs (100%) diff --git a/Winforms.sln b/Winforms.sln index bb00e078623..3c877bff0dd 100644 --- a/Winforms.sln +++ b/Winforms.sln @@ -130,9 +130,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiMonthCalendarTests", "s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiTestsHelper", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauiTestsHelper\MauiTestsHelper.csproj", "{44BB1092-1844-4EAF-8DF5-338DE4C3149A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Primitives.TestUtilities", "src\System.Windows.Forms.Primitives\tests\Utilities\System.Windows.Forms.Primitives.TestUtilities.csproj", "{73B0857A-966B-4E7D-8A83-FECFE0281AB9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Primitives.TestUtilities", "src\System.Windows.Forms.Primitives\tests\TestUtilities\System.Windows.Forms.Primitives.TestUtilities.csproj", "{73B0857A-966B-4E7D-8A83-FECFE0281AB9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.TestUtilities", "src\System.Windows.Forms\tests\Utilities\System.Windows.Forms.TestUtilities.csproj", "{86418F0B-39DC-4B5A-8145-6D607E6150AC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.TestUtilities", "src\System.Windows.Forms\tests\TestUtilities\System.Windows.Forms.TestUtilities.csproj", "{86418F0B-39DC-4B5A-8145-6D607E6150AC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/System.Windows.Forms.Primitives/tests/Utilities/ArchitectureDetection.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/ArchitectureDetection.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Utilities/ArchitectureDetection.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/ArchitectureDetection.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/AssertExtensions.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Extensions/AssertExtensions.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/AssertExtensions.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/Extensions/AssertExtensions.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/TheoryExtensions.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Extensions/TheoryExtensions.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Utilities/Extensions/TheoryExtensions.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/Extensions/TheoryExtensions.cs diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/ITestAccessor.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/ITestAccessor.cs new file mode 100644 index 00000000000..3c632a07d79 --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/ITestAccessor.cs @@ -0,0 +1,56 @@ +// 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. + +namespace System +{ + /// + /// Interface for accessing internals from tests. + /// + /// + /// A non generic representation of the acessor functionality is needed to + /// allow dynamically creating arbitrary from + /// helper methods. + /// + public interface ITestAccessor + { + /// + /// Gets a dynamic accessor to internals on the test object. + /// + /// + /// This does not work for ref structs as they are not yet accessible via reflection. + /// See https://github.com/dotnet/runtime/issues/10057. + /// + dynamic Dynamic { get; } + + /// + /// Creates a delegate for the given non-public method. + /// + /// + /// The method name. If null, uses the name of the delegate for the method. + /// + /// + /// This provides a way to access methods that take ref structs. + /// + /// + /// path); + /// + /// public int InternalGetDirectoryNameOffset(ReadOnlySpan path) + /// { + /// var accessor = typeof(System.IO.Path).TestAccessor(); + /// return accessor.CreateDelegate()(@"C:\Foo"); + /// } + /// + /// // Without ref structs you can just use Func/Action + /// var accessor = typeof(Color).TestAccessor(); + /// bool result = accessor.CreateDelegate>("IsKnownColorSystem")(KnownColor.Window); + /// ]]> + /// + TDelegate CreateDelegate(string methodName = null) + where TDelegate : Delegate; + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/Utilities/NoAssertContext.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/NoAssertContext.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Utilities/NoAssertContext.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/NoAssertContext.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Utilities/System.Windows.Forms.Primitives.TestUtilities.csproj b/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Utilities/System.Windows.Forms.Primitives.TestUtilities.csproj rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessor.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessor.cs new file mode 100644 index 00000000000..b99e77a4b62 --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessor.cs @@ -0,0 +1,211 @@ +// 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.Dynamic; +using System.Linq; +using System.Reflection; + +namespace System +{ + /// + /// Internals (including privates) access wrapper for tests. + /// + /// The type of the class being accessed. + /// + /// Does not allow access to public members- use the object directly. + /// + /// One should strive to *not* access internal state where otherwise avoidable. + /// Ask yourself if you can test the contract of the object in question + /// *without* manipulating internals directly. Often you can. + /// + /// Where internals access is more useful are testing building blocks of more + /// complicated objects, such as internal helper methods or classes. + /// + /// This can be used to access private/internal objects as well via + /// + /// + /// This class can also be derived from to create a strongly typed wrapper + /// that can then be associated via an extension method for the given type + /// to provide consistent discovery and access. + /// + /// + /// { + /// public TestAccessor(Guid instance) : base(instance) {} + /// + /// public int A => Dynamic._a; + /// } + /// + /// public static partial class TestAccessors + /// { + /// public static GuidTestAccessor TestAccessor(this Guid guid) + /// => new GuidTestAccessor(guid); + /// } + /// ]]> + /// + public class TestAccessor : ITestAccessor + { + private static readonly Type s_type = typeof(T); + protected readonly T _instance; + private readonly DynamicWrapper _dynamicWrapper; + + /// The type instance, can be null for statics. + public TestAccessor(T instance) + { + _instance = instance; + _dynamicWrapper = new DynamicWrapper(_instance); + } + + /// + public TDelegate CreateDelegate(string methodName = null) + where TDelegate : Delegate + { + Type type = typeof(TDelegate); + Type[] types = type.GetMethod("Invoke").GetParameters().Select(pi => pi.ParameterType).ToArray(); + + // To make it easier to write a class wrapper with a number of delegates, + // we'll take the name from the delegate itself when unspecified. + if (methodName == null) + methodName = type.Name; + + MethodInfo methodInfo = s_type.GetMethod( + methodName, + BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, + binder: null, + types, + modifiers: null); + + if (methodInfo == null) + throw new ArgumentException($"Could not find non public method {methodName}."); + + return (TDelegate)methodInfo.CreateDelegate(type, methodInfo.IsStatic ? (object)null : _instance); + } + + /// + public dynamic Dynamic => _dynamicWrapper; + + private class DynamicWrapper : DynamicObject + { + private readonly object _instance; + + public DynamicWrapper(object instance) + => _instance = instance; + + public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) + { + result = null; + + MethodInfo methodInfo = null; + Type type = s_type; + + do + { + try + { + methodInfo = type.GetMethod( + binder.Name, + BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); + } + catch (AmbiguousMatchException) + { + // More than one match for the name, specify the arguments + methodInfo = type.GetMethod( + binder.Name, + BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, + binder: null, + args.Select(a => a.GetType()).ToArray(), + modifiers: null); + } + + if (methodInfo != null || type == typeof(object)) + { + // Found something, or already at the top of the type heirarchy + break; + } + + // Walk up the heirarchy + type = type.BaseType; + } while (true); + + if (methodInfo == null) + return false; + + result = methodInfo.Invoke(_instance, args); + return true; + } + + public override bool TrySetMember(SetMemberBinder binder, object value) + { + MemberInfo info = GetFieldOrPropertyInfo(binder.Name); + if (info == null) + return false; + + SetValue(info, value); + return true; + } + + public override bool TryGetMember(GetMemberBinder binder, out object result) + { + result = null; + + MemberInfo info = GetFieldOrPropertyInfo(binder.Name); + if (info == null) + return false; + + result = GetValue(info); + return true; + } + + private MemberInfo GetFieldOrPropertyInfo(string memberName) + { + Type type = s_type; + MemberInfo info; + + do + { + info = (MemberInfo)type.GetField( + memberName, + BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic) + ?? type.GetProperty( + memberName, + BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic); + + if (info != null || type == typeof(object)) + { + // Found something, or already at the top of the type heirarchy + break; + } + + // Walk up the type heirarchy + type = s_type.BaseType; + } while (true); + + return info; + } + + private object GetValue(MemberInfo memberInfo) + => memberInfo switch + { + FieldInfo fieldInfo => fieldInfo.GetValue(_instance), + PropertyInfo propertyInfo => propertyInfo.GetValue(_instance), + _ => throw new InvalidOperationException() + }; + + private void SetValue(MemberInfo memberInfo, object value) + { + switch (memberInfo) + { + case FieldInfo fieldInfo: + fieldInfo.SetValue(_instance, value); + break; + case PropertyInfo propertyInfo: + propertyInfo.SetValue(_instance, value); + break; + default: + throw new InvalidOperationException(); + } + } + } + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessors.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessors.cs new file mode 100644 index 00000000000..c3e4068847c --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/TestAccessors.cs @@ -0,0 +1,57 @@ +// 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.Windows.Forms; + +namespace System +{ + /// + /// Extension methods for associating internals test accessors with + /// types being tested. + /// + /// + /// In the System namespace for implicit discovery. + /// + public static class TestAccessors + { + // Need to pass a null parameter when constructing a static instance + // of TestAccessor. As this is pretty common and never changes, caching + // the array here. + private static object[] s_nullObjectParam = { null }; + + /// + /// Extension that creates a generic internals test accessor for a + /// given instance or Type class (if only accessing statics). + /// + /// + /// Instance or Type class (if only accessing statics). + /// + /// + /// + /// + public static ITestAccessor TestAccessor(this object instanceOrType) + { + if (instanceOrType is Type type) + { + return (ITestAccessor)Activator.CreateInstance( + typeof(TestAccessor<>).MakeGenericType(type), + s_nullObjectParam); + } + else + { + return (ITestAccessor)Activator.CreateInstance( + typeof(TestAccessor<>).MakeGenericType(instanceOrType.GetType()), + instanceOrType); + } + } + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/System/Windows/Forms/FileDialogCustomPlaceTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlaceTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/System/Windows/Forms/FileDialogCustomPlaceTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlaceTests.cs diff --git a/src/System.Windows.Forms.Primitives/tests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs similarity index 100% rename from src/System.Windows.Forms.Primitives/tests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs rename to src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs diff --git a/src/System.Windows.Forms/tests/Utilities/AdminHelpers.cs b/src/System.Windows.Forms/tests/TestUtilities/AdminHelpers.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/AdminHelpers.cs rename to src/System.Windows.Forms/tests/TestUtilities/AdminHelpers.cs diff --git a/src/System.Windows.Forms/tests/Utilities/BinarySerialization.cs b/src/System.Windows.Forms/tests/TestUtilities/BinarySerialization.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/BinarySerialization.cs rename to src/System.Windows.Forms/tests/TestUtilities/BinarySerialization.cs diff --git a/src/System.Windows.Forms/tests/Utilities/CommonMemberDataAttribute.cs b/src/System.Windows.Forms/tests/TestUtilities/CommonMemberDataAttribute.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/CommonMemberDataAttribute.cs rename to src/System.Windows.Forms/tests/TestUtilities/CommonMemberDataAttribute.cs diff --git a/src/System.Windows.Forms/tests/Utilities/CommonTestHelper.cs b/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelper.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/CommonTestHelper.cs rename to src/System.Windows.Forms/tests/TestUtilities/CommonTestHelper.cs diff --git a/src/System.Windows.Forms/tests/Utilities/GdiHelper.cs b/src/System.Windows.Forms/tests/TestUtilities/GdiHelper.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/GdiHelper.cs rename to src/System.Windows.Forms/tests/TestUtilities/GdiHelper.cs diff --git a/src/System.Windows.Forms/tests/Utilities/PlatformDetection.Windows.cs b/src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.Windows.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/PlatformDetection.Windows.cs rename to src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.Windows.cs diff --git a/src/System.Windows.Forms/tests/Utilities/PlatformDetection.cs b/src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/PlatformDetection.cs rename to src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.cs diff --git a/src/System.Windows.Forms/tests/Utilities/System.Windows.Forms.TestUtilities.csproj b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/System.Windows.Forms.TestUtilities.csproj rename to src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj diff --git a/src/System.Windows.Forms/tests/Utilities/TempFile.cs b/src/System.Windows.Forms/tests/TestUtilities/TempFile.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/TempFile.cs rename to src/System.Windows.Forms/tests/TestUtilities/TempFile.cs diff --git a/src/System.Windows.Forms/tests/Utilities/ThreadExceptionFixture.cs b/src/System.Windows.Forms/tests/TestUtilities/ThreadExceptionFixture.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/ThreadExceptionFixture.cs rename to src/System.Windows.Forms/tests/TestUtilities/ThreadExceptionFixture.cs diff --git a/src/System.Windows.Forms/tests/Utilities/WindowClass.cs b/src/System.Windows.Forms/tests/TestUtilities/WindowClass.cs similarity index 100% rename from src/System.Windows.Forms/tests/Utilities/WindowClass.cs rename to src/System.Windows.Forms/tests/TestUtilities/WindowClass.cs From 469a58b6a8cc4fbb54f04077486270a0d7f382e4 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:08:21 +1100 Subject: [PATCH 03/16] System.Windows.Forms.Primitives.Tests compile, some tests commented out --- .../tests/TestUtilities/WindowClass.cs | 203 ++++++++++++++++++ .../Interop/ComCtl32/LVITEMWTests.cs | 2 +- .../Interop/ComCtl32/MCGRIDINFOTests.cs | 2 +- .../Interop/Comdlg32/PRINTDLGWTests.cs | 2 +- .../Interop/NtDll/RtlGetVersionTests.cs | 2 +- .../UnitTests/Interop/Ole32/IPictureTests.cs | 152 ++++++------- .../Interop/Richedit/CHARFORMATWTests.cs | 2 +- .../Interop/Richedit/EDITSTREAMTests.cs | 2 +- .../Interop/User32/GetWindowTextTests.cs | 2 +- .../UnitTests/Interop/User32/LOGFONTWTests.cs | 2 +- .../UnitTests/Interop/User32/SysInfoTests.cs | 2 +- .../Application.ComponentManagerTests.cs} | 2 +- 12 files changed, 289 insertions(+), 86 deletions(-) create mode 100644 src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs rename src/{System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mso/IMsoComponentManagerTests.cs => System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs} (99%) diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs new file mode 100644 index 00000000000..1e603fd05d4 --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs @@ -0,0 +1,203 @@ +// 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; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using static Interop; + +namespace System +{ + internal class WindowClass + { + [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] + public unsafe static extern IntPtr LoadIconW( + IntPtr hInstance, + IntPtr lpIconName); + + private const int CW_USEDEFAULT = unchecked((int)0x80000000); + private const uint IDI_APPLICATION = 32512; + private const uint IDC_ARROW = 32512; + private const int COLOR_WINDOW = 5; + + private static RECT DefaultBounds => new RECT(CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT); + + // Stash the delegate to keep it from being collected + private readonly User32.WNDPROC _windowProcedure; + private User32.WNDCLASS _wndClass; + private readonly string _className; + private readonly string _menuName; + + public ushort Atom { get; private set; } + public IntPtr MainWindow { get; private set; } + public IntPtr ModuleInstance { get; } + + /// + /// Constructor. + /// + /// Name, or default will be generated. + /// Module to associate with the window. The entry assembly is the default. + /// Use (IntPtr)(-1) for no background brush. + /// Use (IntPtr)(-1) for no icon. + /// Use (IntPtr)(-1) for no cursor. + /// Menu name, can not set with . + /// Menu id, can not set with . + public unsafe WindowClass( + string className = default, + IntPtr moduleInstance = default, + User32.CS classStyle = User32.CS.HREDRAW | User32.CS.VREDRAW, + IntPtr backgroundBrush = default, + IntPtr icon = default, + IntPtr cursor = default, + string menuName = null, + int menuId = 0, + int classExtraBytes = 0, + int windowExtraBytes = 0) + { + // Handle default values + className ??= Guid.NewGuid().ToString(); + + if (backgroundBrush == default) + { + backgroundBrush = User32.GetSysColorBrush(COLOR_WINDOW); + } + else if (backgroundBrush == (IntPtr)(-1)) + { + backgroundBrush = default; + } + + if (icon == default) + { + icon = LoadIconW(IntPtr.Zero, (IntPtr)IDI_APPLICATION); + } + else if (icon == (IntPtr)(-1)) + { + icon = default; + } + + if (cursor == default) + { + cursor = User32.LoadCursorW(IntPtr.Zero, (IntPtr)User32.CursorResourceId.IDC_ARROW); + } + else if (cursor == (IntPtr)(-1)) + { + cursor = default; + } + + if (moduleInstance == IntPtr.Zero) + Marshal.GetHINSTANCE(Assembly.GetCallingAssembly().Modules.First()); + + if (menuId != 0 && menuName != null) + throw new ArgumentException($"Can't set both {nameof(menuName)} and {nameof(menuId)}."); + + _windowProcedure = WNDPROC; + ModuleInstance = moduleInstance; + + _className = className; + _menuName = menuName ?? string.Empty; + + _wndClass = new User32.WNDCLASS + { + style = classStyle, + lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), + cbClsExtra = classExtraBytes, + cbWndExtra = windowExtraBytes, + hInstance = moduleInstance, + hIcon = icon, + hCursor = cursor, + hbrBackground = backgroundBrush, + lpszMenuName = (char*)menuId + }; + } + + public bool IsRegistered => Atom != 0; + + public unsafe WindowClass Register() + { + fixed (char* name = _className) + fixed (char* menuName = _menuName) + { + _wndClass.lpszClassName = name; + if (!string.IsNullOrEmpty(_menuName)) + _wndClass.lpszMenuName = menuName; + + ushort atom = User32.RegisterClassW(ref _wndClass); + if (atom == 0) + { + throw new Win32Exception(); + } + Atom = atom; + return this; + } + } + + public IntPtr CreateWindow( + string windowName = null, + User32.WS style = User32.WS.OVERLAPPED, + User32.WS_EX extendedStyle = default, + bool isMainWindow = false, + IntPtr parentWindow = default, + IntPtr parameters = default, + IntPtr menuHandle = default) + { + return CreateWindow( + DefaultBounds, + windowName, + style, + extendedStyle, + isMainWindow, + parentWindow, + parameters, + menuHandle); + } + + public unsafe IntPtr CreateWindow( + RECT bounds, + string windowName = null, + User32.WS style = User32.WS.OVERLAPPED, + User32.WS_EX extendedStyle = default, + bool isMainWindow = false, + IntPtr parentWindow = default, + IntPtr parameters = default, + IntPtr menuHandle = default) + { + if (!IsRegistered) + throw new ArgumentException("Window class must be registered before using."); + + IntPtr window = User32.CreateWindowExW( + dwExStyle: extendedStyle, + lpClassName: (char*)Atom, + lpWindowName: windowName, + dwStyle: style, + X: bounds.X, + Y: bounds.Y, + nWidth: bounds.Width, + nHeight: bounds.Height, + hWndParent: parentWindow, + hMenu: menuHandle, + hInst: IntPtr.Zero, + lpParam: parameters); + + if (isMainWindow) + MainWindow = window; + + return window; + } + + protected virtual IntPtr WNDPROC(IntPtr hWnd, User32.WM msg, IntPtr wParam, IntPtr lParam) + { + switch (msg) + { + case User32.WM.DESTROY: + if (hWnd == MainWindow) + User32.PostQuitMessage(0); + return (IntPtr)0; + } + + return User32.DefWindowProcW(hWnd, msg, wParam, lParam); + } + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/LVITEMWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/LVITEMWTests.cs index 3359170dd7d..54bcd63e778 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/LVITEMWTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/LVITEMWTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Tests.InteropTests { - public class LVITEMWTests : IClassFixture + public class LVITEMWTests { [Fact] public unsafe void UpdateText_should_throw_AOOR_if_cchTextMax_less_than_1() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs index 838c009712e..62f8bb1d042 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.ComCtl32 { - public class MCGRIDINFOTests : IClassFixture + public class MCGRIDINFOTests { [ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] public unsafe void MCGRIDINFO_x32_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs index 9ef53777b33..71cb48fbb5c 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Comdlg32 { - public class PRINTDLGWTests : IClassFixture + public class PRINTDLGWTests { [ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] public unsafe void PRINTDLGW_32_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/NtDll/RtlGetVersionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/NtDll/RtlGetVersionTests.cs index 17fac989395..a14170d2428 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/NtDll/RtlGetVersionTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/NtDll/RtlGetVersionTests.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.NtDll { - public class RtlGetVersionTests : IClassFixture + public class RtlGetVersionTests { [Fact] public void BasicFunctionality() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs index c17a1df8424..fb5096e9cd1 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs @@ -2,93 +2,93 @@ // 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.Drawing; -using Xunit; -using static Interop.Ole32; +// using System.Drawing; +// using Xunit; +// using static Interop.Ole32; -namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32 -{ - public class IPictureTests : IClassFixture - { - [Fact] - public void GetIPictureFromCursor() - { - Cursor arrow = Cursors.Arrow; - IPicture picture = AxHostAccess.GetIPictureFromCursor(arrow); - Assert.NotNull(picture); - Assert.Equal(PICTYPE.ICON, (PICTYPE)picture.Type); +// namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32 +// { +// public class IPictureTests +// { +// [Fact] +// public void GetIPictureFromCursor() +// { +// Cursor arrow = Cursors.Arrow; +// IPicture picture = AxHostAccess.GetIPictureFromCursor(arrow); +// Assert.NotNull(picture); +// Assert.Equal(PICTYPE.ICON, (PICTYPE)picture.Type); - Assert.Equal(arrow.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); - Assert.Equal(arrow.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); - } +// Assert.Equal(arrow.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); +// Assert.Equal(arrow.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); +// } - [Fact] - public void GetIPictureFromImage() - { - using Icon icon = Icon.FromHandle(Cursors.Arrow.Handle); - using Bitmap bitmap = icon.ToBitmap(); - IPicture picture = AxHostAccess.GetIPictureFromPicture(bitmap); - Assert.NotNull(picture); - Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); +// [Fact] +// public void GetIPictureFromImage() +// { +// using Icon icon = Icon.FromHandle(Cursors.Arrow.Handle); +// using Bitmap bitmap = icon.ToBitmap(); +// IPicture picture = AxHostAccess.GetIPictureFromPicture(bitmap); +// Assert.NotNull(picture); +// Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); - Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); - Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); - } +// Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); +// Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); +// } - [Fact] - public void GetIPictureDispFromImage() - { - using Icon icon = SystemIcons.Question; - using Bitmap bitmap = icon.ToBitmap(); - IPictureDisp picture = AxHostAccess.GetIPictureDispFromPicture(bitmap); - Assert.NotNull(picture); - Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); +// [Fact] +// public void GetIPictureDispFromImage() +// { +// using Icon icon = SystemIcons.Question; +// using Bitmap bitmap = icon.ToBitmap(); +// IPictureDisp picture = AxHostAccess.GetIPictureDispFromPicture(bitmap); +// Assert.NotNull(picture); +// Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); - Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); - Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); - } +// Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); +// Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); +// } - [Fact] - public void GetPictureFromIPicture() - { - using Icon icon = SystemIcons.Exclamation; - using Bitmap bitmap = icon.ToBitmap(); - IPicture picture = AxHostAccess.GetIPictureFromPicture(bitmap); - Assert.NotNull(picture); - using Image image = AxHostAccess.GetPictureFromIPicture(picture); - Assert.NotNull(image); - Assert.Equal(bitmap.Size, image.Size); - } +// [Fact] +// public void GetPictureFromIPicture() +// { +// using Icon icon = SystemIcons.Exclamation; +// using Bitmap bitmap = icon.ToBitmap(); +// IPicture picture = AxHostAccess.GetIPictureFromPicture(bitmap); +// Assert.NotNull(picture); +// using Image image = AxHostAccess.GetPictureFromIPicture(picture); +// Assert.NotNull(image); +// Assert.Equal(bitmap.Size, image.Size); +// } - [Fact] - public void GetPictureFromIPictureDisp() - { - using Bitmap bitmap = new Bitmap(100, 200); - IPictureDisp picture = AxHostAccess.GetIPictureDispFromPicture(bitmap); - Assert.NotNull(picture); - using Image image = AxHostAccess.GetPictureFromIPictureDisp(picture); - Assert.NotNull(image); - Assert.Equal(bitmap.Size, image.Size); - } +// [Fact] +// public void GetPictureFromIPictureDisp() +// { +// using Bitmap bitmap = new Bitmap(100, 200); +// IPictureDisp picture = AxHostAccess.GetIPictureDispFromPicture(bitmap); +// Assert.NotNull(picture); +// using Image image = AxHostAccess.GetPictureFromIPictureDisp(picture); +// Assert.NotNull(image); +// Assert.Equal(bitmap.Size, image.Size); +// } - internal class AxHostAccess : AxHost - { - private AxHostAccess() : base(string.Empty) { } +// internal class AxHostAccess : AxHost +// { +// private AxHostAccess() : base(string.Empty) { } - internal new static IPicture GetIPictureFromCursor(Cursor cursor) - => (IPicture)AxHost.GetIPictureFromCursor(cursor); +// internal new static IPicture GetIPictureFromCursor(Cursor cursor) +// => (IPicture)AxHost.GetIPictureFromCursor(cursor); - internal new static IPicture GetIPictureFromPicture(Image image) - => (IPicture)AxHost.GetIPictureFromPicture(image); +// internal new static IPicture GetIPictureFromPicture(Image image) +// => (IPicture)AxHost.GetIPictureFromPicture(image); - internal new static IPictureDisp GetIPictureDispFromPicture(Image image) - => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); +// internal new static IPictureDisp GetIPictureDispFromPicture(Image image) +// => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); - internal static Image GetPictureFromIPicture(IPicture picture) - => GetPictureFromIPicture((object)picture); +// internal static Image GetPictureFromIPicture(IPicture picture) +// => GetPictureFromIPicture((object)picture); - internal static Image GetPictureFromIPictureDisp(IPictureDisp picture) - => GetPictureFromIPictureDisp((object)picture); - } - } -} +// internal static Image GetPictureFromIPictureDisp(IPictureDisp picture) +// => GetPictureFromIPictureDisp((object)picture); +// } +// } +// } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/CHARFORMATWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/CHARFORMATWTests.cs index 1797970c1f3..f28ce42598f 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/CHARFORMATWTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/CHARFORMATWTests.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Tests.Interop.Richedit { - public class CHARFORMATWTests : IClassFixture + public class CHARFORMATWTests { [Fact] public unsafe void CharFormat_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs index deeb232417c..67a9e2921e7 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Tests.Interop.Richedit { - public class EDITSTREAMTests : IClassFixture + public class EDITSTREAMTests { [WinFormsFact] public unsafe void EditStream_Size_Get_ReturnsExpected() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs index 87035132bbd..7651ae7baea 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/LOGFONTWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/LOGFONTWTests.cs index 89de4647a13..89befafc2f6 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/LOGFONTWTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/LOGFONTWTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.User32 { - public class LOGFONTWTests : IClassFixture + public class LOGFONTWTests { [Fact] public unsafe void LogFont_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/SysInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/SysInfoTests.cs index 0d4c9bfd2b2..ba8f6c19639 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/SysInfoTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/SysInfoTests.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.User32 { - public class SysInfoTests : IClassFixture + public class SysInfoTests { [Fact] public unsafe void NonClientMetrics_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mso/IMsoComponentManagerTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs similarity index 99% rename from src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mso/IMsoComponentManagerTests.cs rename to src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs index 8ec521c08ec..28c6fb69be7 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mso/IMsoComponentManagerTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs @@ -8,7 +8,7 @@ using static Interop; using static Interop.Mso; -namespace System.Windows.Forms.Primitives.Tests.Interop.Mso +namespace System.Windows.Forms.Tests.Interop.Mso { public unsafe class IMsoComponentManagerTests : IClassFixture { From 40d7e3f6b311afda88b744f8cd20aad23c16d767 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:19:52 +1100 Subject: [PATCH 04/16] System.Windows.Forms.Tests compile --- .../src/Properties/InternalsVisibleTo.cs | 5 +++-- .../tests/TestUtilities/CommonTestHelper.cs | 4 ++-- .../System.Windows.Forms.TestUtilities.csproj | 11 +++++++++++ .../UnitTests/System.Windows.Forms.Tests.csproj | 12 +----------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/src/Properties/InternalsVisibleTo.cs b/src/System.Windows.Forms.Primitives/src/Properties/InternalsVisibleTo.cs index 02ca6491933..348b2ca8d03 100644 --- a/src/System.Windows.Forms.Primitives/src/Properties/InternalsVisibleTo.cs +++ b/src/System.Windows.Forms.Primitives/src/Properties/InternalsVisibleTo.cs @@ -8,11 +8,12 @@ [assembly: InternalsVisibleTo("System.Windows.Forms.Design, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("System.Windows.Forms.Design.Editors, PublicKey=00000000000000000400000000000000")] +[assembly: InternalsVisibleTo("System.Windows.Forms.Design.Tests, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("System.Windows.Forms.Primitives.Tests, PublicKey=00000000000000000400000000000000")] +[assembly: InternalsVisibleTo("System.Windows.Forms.Primitives.TestUtilities, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("System.Windows.Forms.Tests, PublicKey=00000000000000000400000000000000")] -[assembly: InternalsVisibleTo("System.Windows.Forms.Design.Tests, PublicKey=00000000000000000400000000000000")] +[assembly: InternalsVisibleTo("System.Windows.Forms.TestUtilities, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("WinformsControlsTest, PublicKey=00000000000000000400000000000000")] -[assembly: InternalsVisibleTo("InternalUtilitiesForTests, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("MauiListViewTests, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("System.Windows.Forms.IntegrationTests.Common, PublicKey=00000000000000000400000000000000")] [assembly: InternalsVisibleTo("System.Windows.Forms.Maui.IntegrationTests, PublicKey=00000000000000000400000000000000")] diff --git a/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelper.cs b/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelper.cs index d2767ae6532..ed166b0a7f4 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelper.cs +++ b/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelper.cs @@ -20,7 +20,7 @@ namespace WinForms.Common.Tests public static class CommonTestHelper { // helper method to generate theory data from all values of an enum type - internal static TheoryData GetEnumTheoryData() where T : Enum + public static TheoryData GetEnumTheoryData() where T : Enum { var data = new TheoryData(); foreach (T item in Enum.GetValues(typeof(T))) @@ -43,7 +43,7 @@ public static TheoryData GetEnumTypeTheoryData(Type enumType) // helper method to generate invalid theory data for an enum type // This method assumes that int.MinValue and int.MaxValue are not in the enum - internal static TheoryData GetEnumTheoryDataInvalid() where T : Enum + public static TheoryData GetEnumTheoryDataInvalid() where T : Enum { var data = new TheoryData { diff --git a/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj index 56ed147a54a..15d5a467ffa 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj +++ b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj @@ -5,8 +5,19 @@ System + + + + + + + + + + + diff --git a/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj b/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj index 4162eae72bf..c5ed858cc56 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj +++ b/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj @@ -16,9 +16,7 @@ - - - + @@ -26,14 +24,6 @@ - - - - - - - - PreserveNewest From 990232abb2bbf86b6398cf738410c5a25931583d Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:27:32 +1100 Subject: [PATCH 05/16] Microsoft.VisualBasic.Tests compile --- .../UnitTests/Microsoft.VisualBasic.Tests.csproj | 11 ++++------- .../tests/TestUtilities/PlatformDetection.Windows.cs | 0 .../tests/TestUtilities/PlatformDetection.cs | 0 ...stem.Windows.Forms.Primitives.TestUtilities.csproj | 4 ++++ 4 files changed, 8 insertions(+), 7 deletions(-) rename src/{System.Windows.Forms => System.Windows.Forms.Primitives}/tests/TestUtilities/PlatformDetection.Windows.cs (100%) rename src/{System.Windows.Forms => System.Windows.Forms.Primitives}/tests/TestUtilities/PlatformDetection.cs (100%) diff --git a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj index 6cdbde8c0b0..6d1366ef6f2 100644 --- a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj +++ b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj @@ -6,17 +6,14 @@ + + + + - - - - - - - diff --git a/src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.Windows.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.Windows.cs similarity index 100% rename from src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.Windows.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.Windows.cs diff --git a/src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.cs similarity index 100% rename from src/System.Windows.Forms/tests/TestUtilities/PlatformDetection.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.cs diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj b/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj index c796dd8302f..2848fc195c3 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj @@ -14,4 +14,8 @@ + + + + From f5194ed9ccfa5490f2ee03a9d7a46bcf421ff376 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:37:15 +1100 Subject: [PATCH 06/16] Work --- Winforms.sln | 7 ------- .../Microsoft.VisualBasic.IntegrationTests.csproj | 1 - .../UnitTests/System.Windows.Forms.Design.Tests.csproj | 5 +---- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Winforms.sln b/Winforms.sln index 3c877bff0dd..8f39430544d 100644 --- a/Winforms.sln +++ b/Winforms.sln @@ -37,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Integr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Drawing.Facade", "src\System.Drawing\src\System.Drawing.Facade.csproj", "{F1B0790A-1A40-4487-A607-36D21D827E44}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InternalUtilitiesForTests", "src\Common\tests\InternalUtilitiesForTests\InternalUtilitiesForTests.csproj", "{3603561D-907D-494B-9E3C-29D7001018F6}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Accessibility", "src\Accessibility\src\Accessibility.ilproj", "{351D8601-6E21-45E8-B3B9-847C4540BD4E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Accessibility-version", "src\Accessibility\ver\Accessibility-version.csproj", "{6103E743-057D-41C6-946C-23A751A08748}" @@ -184,10 +182,6 @@ Global {F1B0790A-1A40-4487-A607-36D21D827E44}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1B0790A-1A40-4487-A607-36D21D827E44}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1B0790A-1A40-4487-A607-36D21D827E44}.Release|Any CPU.Build.0 = Release|Any CPU - {3603561D-907D-494B-9E3C-29D7001018F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3603561D-907D-494B-9E3C-29D7001018F6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3603561D-907D-494B-9E3C-29D7001018F6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3603561D-907D-494B-9E3C-29D7001018F6}.Release|Any CPU.Build.0 = Release|Any CPU {351D8601-6E21-45E8-B3B9-847C4540BD4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {351D8601-6E21-45E8-B3B9-847C4540BD4E}.Debug|Any CPU.Build.0 = Debug|Any CPU {351D8601-6E21-45E8-B3B9-847C4540BD4E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -290,7 +284,6 @@ Global {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A} = {DF68A171-D27B-4E6A-8A7E-63A651622355} {238195CE-7CCE-4469-ACD8-EA00E88D947A} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A} {F1B0790A-1A40-4487-A607-36D21D827E44} = {434C00C3-E498-4BA7-9764-9F0FC8CFE457} - {3603561D-907D-494B-9E3C-29D7001018F6} = {DF68A171-D27B-4E6A-8A7E-63A651622355} {351D8601-6E21-45E8-B3B9-847C4540BD4E} = {088DD24C-DF6B-45F3-A8BC-592580A4B2A9} {6103E743-057D-41C6-946C-23A751A08748} = {088DD24C-DF6B-45F3-A8BC-592580A4B2A9} {088DD24C-DF6B-45F3-A8BC-592580A4B2A9} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7} diff --git a/src/Microsoft.VisualBasic/tests/IntegrationTests/Microsoft.VisualBasic.IntegrationTests/Microsoft.VisualBasic.IntegrationTests.csproj b/src/Microsoft.VisualBasic/tests/IntegrationTests/Microsoft.VisualBasic.IntegrationTests/Microsoft.VisualBasic.IntegrationTests.csproj index 315685c7e0e..ca9ed1d3242 100644 --- a/src/Microsoft.VisualBasic/tests/IntegrationTests/Microsoft.VisualBasic.IntegrationTests/Microsoft.VisualBasic.IntegrationTests.csproj +++ b/src/Microsoft.VisualBasic/tests/IntegrationTests/Microsoft.VisualBasic.IntegrationTests/Microsoft.VisualBasic.IntegrationTests.csproj @@ -2,7 +2,6 @@ - diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj b/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj index 5112042edde..a6d7f3a4b52 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj @@ -15,13 +15,10 @@ + - - - - From 857ab80a04a8c2183f84affc6704b8652305a2bb Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 26 Mar 2020 16:55:47 +1100 Subject: [PATCH 07/16] fixup! System.Windows.Forms.Primitives.Tests compile, some tests commented out --- .../tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs index 67a9e2921e7..f2801571ed8 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Richedit/EDITSTREAMTests.cs @@ -9,7 +9,7 @@ namespace System.Windows.Forms.Tests.Interop.Richedit { public class EDITSTREAMTests { - [WinFormsFact] + [Fact] public unsafe void EditStream_Size_Get_ReturnsExpected() { if (IntPtr.Size == 4) From ac17eabee19e334d391265ecde71e2ca94d1c348 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 1 Apr 2020 14:45:57 +1100 Subject: [PATCH 08/16] Fixes after rebase --- .../tests/UnitTests/Interop/User32/GetWindowTextTests.cs | 2 +- .../System/Windows/Forms/Application.ComponentManagerTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs index 7651ae7baea..1890912a20d 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.User32 { - public class GetWindowTextTests : IClassFixture + public class GetWindowTextTests { [WinFormsFact] public void GetWindowText_DoesNotTruncateText() diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs index 28c6fb69be7..641e0d71147 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ComponentManagerTests.cs @@ -8,7 +8,7 @@ using static Interop; using static Interop.Mso; -namespace System.Windows.Forms.Tests.Interop.Mso +namespace System.Windows.Forms.Tests.Interop_Mso { public unsafe class IMsoComponentManagerTests : IClassFixture { From 545217caf7d1caeabeae1a9dd8011ad09c82c0f8 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 2 Apr 2020 14:05:58 +1100 Subject: [PATCH 09/16] More fixes --- .../tests/UnitTests/Interop/User32/GetWindowTextTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs index 1890912a20d..a07340133c9 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs @@ -9,13 +9,13 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.User32 { public class GetWindowTextTests { - [WinFormsFact] + [StaFact] public void GetWindowText_DoesNotTruncateText() { CallGetWindowText(useBeforeGetTextLengthCallback: false); } - [WinFormsFact] + [StaFact] public void GetWindowText_DoesNotLoopInfinitely() { CallGetWindowText(useBeforeGetTextLengthCallback: true); From 87981c045a260c5bb7d241ef4dc648d3ee0b6d23 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 27 May 2020 13:57:09 +1000 Subject: [PATCH 10/16] . --- .../tests/TestUtilities/WindowClass.cs | 202 ------------------ 1 file changed, 202 deletions(-) delete mode 100644 src/System.Windows.Forms/tests/TestUtilities/WindowClass.cs diff --git a/src/System.Windows.Forms/tests/TestUtilities/WindowClass.cs b/src/System.Windows.Forms/tests/TestUtilities/WindowClass.cs deleted file mode 100644 index 2def115488a..00000000000 --- a/src/System.Windows.Forms/tests/TestUtilities/WindowClass.cs +++ /dev/null @@ -1,202 +0,0 @@ -// 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; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using static Interop; - -namespace System -{ - internal class WindowClass - { - [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] - public unsafe static extern IntPtr LoadIconW( - IntPtr hInstance, - IntPtr lpIconName); - - private const int CW_USEDEFAULT = unchecked((int)0x80000000); - private const uint IDI_APPLICATION = 32512; - private const int COLOR_WINDOW = 5; - - private static RECT DefaultBounds => new RECT(CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT); - - // Stash the delegate to keep it from being collected - private readonly User32.WNDPROC _windowProcedure; - private User32.WNDCLASS _wndClass; - private readonly string _className; - private readonly string _menuName; - - public ushort Atom { get; private set; } - public IntPtr MainWindow { get; private set; } - public IntPtr ModuleInstance { get; } - - /// - /// Constructor. - /// - /// Name, or default will be generated. - /// Module to associate with the window. The entry assembly is the default. - /// Use (IntPtr)(-1) for no background brush. - /// Use (IntPtr)(-1) for no icon. - /// Use (IntPtr)(-1) for no cursor. - /// Menu name, can not set with . - /// Menu id, can not set with . - public unsafe WindowClass( - string className = default, - IntPtr moduleInstance = default, - User32.CS classStyle = User32.CS.HREDRAW | User32.CS.VREDRAW, - IntPtr backgroundBrush = default, - IntPtr icon = default, - IntPtr cursor = default, - string menuName = null, - int menuId = 0, - int classExtraBytes = 0, - int windowExtraBytes = 0) - { - // Handle default values - className ??= Guid.NewGuid().ToString(); - - if (backgroundBrush == default) - { - backgroundBrush = User32.GetSysColorBrush(COLOR_WINDOW); - } - else if (backgroundBrush == (IntPtr)(-1)) - { - backgroundBrush = default; - } - - if (icon == default) - { - icon = LoadIconW(IntPtr.Zero, (IntPtr)IDI_APPLICATION); - } - else if (icon == (IntPtr)(-1)) - { - icon = default; - } - - if (cursor == default) - { - cursor = User32.LoadCursorW(IntPtr.Zero, (IntPtr)User32.CursorResourceId.IDC_ARROW); - } - else if (cursor == (IntPtr)(-1)) - { - cursor = default; - } - - if (moduleInstance == IntPtr.Zero) - Marshal.GetHINSTANCE(Assembly.GetCallingAssembly().Modules.First()); - - if (menuId != 0 && menuName != null) - throw new ArgumentException($"Can't set both {nameof(menuName)} and {nameof(menuId)}."); - - _windowProcedure = WNDPROC; - ModuleInstance = moduleInstance; - - _className = className; - _menuName = menuName ?? string.Empty; - - _wndClass = new User32.WNDCLASS - { - style = classStyle, - lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), - cbClsExtra = classExtraBytes, - cbWndExtra = windowExtraBytes, - hInstance = moduleInstance, - hIcon = icon, - hCursor = cursor, - hbrBackground = backgroundBrush, - lpszMenuName = (char*)menuId - }; - } - - public bool IsRegistered => Atom != 0; - - public unsafe WindowClass Register() - { - fixed (char* name = _className) - fixed (char* menuName = _menuName) - { - _wndClass.lpszClassName = name; - if (!string.IsNullOrEmpty(_menuName)) - _wndClass.lpszMenuName = menuName; - - ushort atom = User32.RegisterClassW(ref _wndClass); - if (atom == 0) - { - throw new Win32Exception(); - } - Atom = atom; - return this; - } - } - - public IntPtr CreateWindow( - string windowName = null, - User32.WS style = User32.WS.OVERLAPPED, - User32.WS_EX extendedStyle = default, - bool isMainWindow = false, - IntPtr parentWindow = default, - IntPtr parameters = default, - IntPtr menuHandle = default) - { - return CreateWindow( - DefaultBounds, - windowName, - style, - extendedStyle, - isMainWindow, - parentWindow, - parameters, - menuHandle); - } - - public unsafe IntPtr CreateWindow( - RECT bounds, - string windowName = null, - User32.WS style = User32.WS.OVERLAPPED, - User32.WS_EX extendedStyle = default, - bool isMainWindow = false, - IntPtr parentWindow = default, - IntPtr parameters = default, - IntPtr menuHandle = default) - { - if (!IsRegistered) - throw new ArgumentException("Window class must be registered before using."); - - IntPtr window = User32.CreateWindowExW( - dwExStyle: extendedStyle, - lpClassName: (char*)Atom, - lpWindowName: windowName, - dwStyle: style, - X: bounds.X, - Y: bounds.Y, - nWidth: bounds.Width, - nHeight: bounds.Height, - hWndParent: parentWindow, - hMenu: menuHandle, - hInst: IntPtr.Zero, - lpParam: parameters); - - if (isMainWindow) - MainWindow = window; - - return window; - } - - protected virtual IntPtr WNDPROC(IntPtr hWnd, User32.WM msg, IntPtr wParam, IntPtr lParam) - { - switch (msg) - { - case User32.WM.DESTROY: - if (hWnd == MainWindow) - User32.PostQuitMessage(0); - return (IntPtr)0; - } - - return User32.DefWindowProcW(hWnd, msg, wParam, lParam); - } - } -} From ad8258d424b2e52afb7216f85ecaec8d71f9d3b0 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 27 May 2020 16:26:33 +1000 Subject: [PATCH 11/16] . --- src/Common/tests/Directory.Build.props | 7 -- .../InternalUtilitiesForTests.csproj | 22 ---- src/Common/tests/NoAssertContext.cs | 111 ------------------ .../Microsoft.VisualBasic.Tests.csproj | 2 +- .../System.Windows.Forms.Design.Tests.csproj | 2 +- .../Properties}/InternalsVisibleTo.cs | 0 .../tests/TestUtilities/WindowClass.cs | 1 - .../TASKDIALOGCONFIGIconUnionTests.cs | 2 +- .../Interop/ComCtl32/TASKDIALOGCONFIGTests.cs | 2 +- .../ComCtl32/TASKDIALOG_BUTTONTests.cs | 2 +- .../Interop/Oleaut32/IDispatchTests.cs | 2 +- .../Interop/Oleaut32/ITypeInfoTests.cs | 2 +- ...stem.Windows.Forms.Primitives.Tests.csproj | 2 +- .../Forms/FileDialogCustomPlaceTests.cs | 30 ++++- .../FileDialogCustomPlacesCollectionTests.cs | 26 +++- .../System.Windows.Forms.TestUtilities.csproj | 2 +- .../TestUtilities}/SystemEventsHelper.cs | 2 +- .../System.Windows.Forms.Tests.csproj | 2 +- 18 files changed, 59 insertions(+), 160 deletions(-) delete mode 100644 src/Common/tests/Directory.Build.props delete mode 100644 src/Common/tests/InternalUtilitiesForTests/InternalUtilitiesForTests.csproj delete mode 100644 src/Common/tests/NoAssertContext.cs rename src/{Common/tests/InternalUtilitiesForTests => System.Windows.Forms.Primitives/tests/TestUtilities/Properties}/InternalsVisibleTo.cs (100%) rename src/{Common/tests => System.Windows.Forms/tests/TestUtilities}/SystemEventsHelper.cs (99%) diff --git a/src/Common/tests/Directory.Build.props b/src/Common/tests/Directory.Build.props deleted file mode 100644 index a01177951bc..00000000000 --- a/src/Common/tests/Directory.Build.props +++ /dev/null @@ -1,7 +0,0 @@ - - - - - ECMA - - diff --git a/src/Common/tests/InternalUtilitiesForTests/InternalUtilitiesForTests.csproj b/src/Common/tests/InternalUtilitiesForTests/InternalUtilitiesForTests.csproj deleted file mode 100644 index cb833482993..00000000000 --- a/src/Common/tests/InternalUtilitiesForTests/InternalUtilitiesForTests.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - InternalUtilitiesForTests - true - - - - - - - - - - - - - - - - - - diff --git a/src/Common/tests/NoAssertContext.cs b/src/Common/tests/NoAssertContext.cs deleted file mode 100644 index 466087b0d98..00000000000 --- a/src/Common/tests/NoAssertContext.cs +++ /dev/null @@ -1,111 +0,0 @@ -// 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.Generic; -using System.Diagnostics; -using System.Threading; - -namespace System -{ - /// - /// Use (within a using) to eat asserts. - /// - public sealed class NoAssertContext : IDisposable - { - private static readonly object s_lock = new object(); - private static readonly HashSet s_suppressedThreads = new HashSet(); - private static TraceListener s_defaultListener; - private static readonly NoAssertListener s_noAssertListener = new NoAssertListener(); - - public NoAssertContext() - { - lock (s_lock) - { - s_suppressedThreads.Add(Thread.CurrentThread.ManagedThreadId); - if (s_suppressedThreads.Count == 1) - { - // Hook our custom listener first so we don't lose assertions from other threads when - // we disconnect the default listener. - Trace.Listeners.Add(s_noAssertListener); - - // "Default" is the listener that terminates the process when debug assertions fail. - s_defaultListener = Trace.Listeners["Default"]; - Trace.Listeners.Remove(s_defaultListener); - } - } - } - - public void Dispose() - { - GC.SuppressFinalize(this); - - lock (s_lock) - { - s_suppressedThreads.Remove(Thread.CurrentThread.ManagedThreadId); - if (s_suppressedThreads.Count == 0 && s_defaultListener != null) - { - // Add the default listener back first to make sure we don't lose any - // asserts from other threads. - Trace.Listeners.Add(s_defaultListener); - Trace.Listeners.Remove(s_noAssertListener); - s_defaultListener = null; - } - } - } - - ~NoAssertContext() - { - // We need this class to be used in a using to effectively rationalize about a test. - throw new InvalidOperationException($"Did not dispose {nameof(NoAssertContext)}"); - } - - private class NoAssertListener : TraceListener - { - public NoAssertListener() - : base(typeof(NoAssertListener).FullName) - { - } - - public override void Fail(string message) - { - lock (s_lock) - { - if (!s_suppressedThreads.Contains(Thread.CurrentThread.ManagedThreadId)) - { - s_defaultListener?.Fail(message); - } - } - } - - public override void Fail(string message, string detailMessage) - { - lock (s_lock) - { - if (!s_suppressedThreads.Contains(Thread.CurrentThread.ManagedThreadId)) - { - s_defaultListener?.Fail(message, detailMessage); - } - } - } - - // Write and WriteLine are virtual - - public override void Write(string message) - { - lock (s_lock) - { - s_defaultListener?.Write(message); - } - } - - public override void WriteLine(string message) - { - lock (s_lock) - { - s_defaultListener?.WriteLine(message); - } - } - } - } -} diff --git a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj index 6d1366ef6f2..4a1ed48e401 100644 --- a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj +++ b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft.VisualBasic.Tests.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj b/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj index a6d7f3a4b52..103ab50d46d 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Common/tests/InternalUtilitiesForTests/InternalsVisibleTo.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Properties/InternalsVisibleTo.cs similarity index 100% rename from src/Common/tests/InternalUtilitiesForTests/InternalsVisibleTo.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/Properties/InternalsVisibleTo.cs diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs index 1e603fd05d4..2def115488a 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/WindowClass.cs @@ -20,7 +20,6 @@ public unsafe static extern IntPtr LoadIconW( private const int CW_USEDEFAULT = unchecked((int)0x80000000); private const uint IDI_APPLICATION = 32512; - private const uint IDC_ARROW = 32512; private const int COLOR_WINDOW = 5; private static RECT DefaultBounds => new RECT(CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT); diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs index bf7b70ff408..a79c4cdd230 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.ComCtl32 { - public class TASKDIALOGCONFIGIconUnionTests : IClassFixture + public class TASKDIALOGCONFIGIconUnionTests { [ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] public unsafe void TASKDIALOGCONFIGIconUnion_x32_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs index ff9edd16f76..331ce4abc2f 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.ComCtl32 { - public class TASKDIALOGCONFIGTests : IClassFixture + public class TASKDIALOGCONFIGTests { [ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] public unsafe void TASKDIALOGCONFIG_x32_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs index 70a83515c7f..05d9b766d9f 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs @@ -8,7 +8,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.ComCtl32 { - public class TASKDIALOG_BUTTONTests : IClassFixture + public class TASKDIALOG_BUTTONTests { [ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] public unsafe void TASKDIALOG_BUTTON_x32_Size() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs index 83be7f5fbee..fcf977f3903 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs @@ -11,7 +11,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 { [Collection("Sequential")] - public class IDispatchTests : IClassFixture + public class IDispatchTests { [WinFormsFact] public unsafe void IDispatch_GetIDsOfNames_Invoke_Success() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs index 2e7eba55a63..cea88ba56f9 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs @@ -12,7 +12,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 { [Collection("Sequential")] - public class ITypeInfoTests : IClassFixture + public class ITypeInfoTests { [WinFormsFact] public unsafe void ITypeInfo_AddressOfMember_Invoke_Success() diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj index c83401cbca5..412b1f02061 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlaceTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlaceTests.cs index c9e069a9e7e..24374dfb313 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlaceTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlaceTests.cs @@ -3,15 +3,25 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using WinForms.Common.Tests; using Xunit; namespace System.Windows.Forms.Tests { public class FileDialogCustomPlaceTests { + public static TheoryData GetStringWithNullTheoryData() + { + var data = new TheoryData + { + null, + string.Empty, + "reasonable" + }; + return data; + } + [Theory] - [CommonMemberData(nameof(CommonTestHelper.GetStringWithNullTheoryData))] + [MemberData(nameof(GetStringWithNullTheoryData))] public void FileDialogCustomPlace_Ctor_String(string path) { var place = new FileDialogCustomPlace(path); @@ -19,8 +29,18 @@ public void FileDialogCustomPlace_Ctor_String(string path) Assert.Same(path ?? string.Empty, place.Path); } + public static TheoryData GetGuidTheoryData() + { + var data = new TheoryData + { + Guid.Empty, + Guid.NewGuid() + }; + return data; + } + [Theory] - [CommonMemberData(nameof(CommonTestHelper.GetGuidTheoryData))] + [MemberData(nameof(GetGuidTheoryData))] public void FileDialogCustomPlace_Ctor_Guid(Guid knownFolderGuid) { var place = new FileDialogCustomPlace(knownFolderGuid); @@ -29,7 +49,7 @@ public void FileDialogCustomPlace_Ctor_Guid(Guid knownFolderGuid) } [Theory] - [CommonMemberData(nameof(CommonTestHelper.GetGuidTheoryData))] + [MemberData(nameof(GetGuidTheoryData))] public void FileDialogCustomPlace_KnownFolderGuid_Set_GetReturnsExpected(Guid value) { var place = new FileDialogCustomPlace("path") @@ -46,7 +66,7 @@ public void FileDialogCustomPlace_KnownFolderGuid_Set_GetReturnsExpected(Guid va } [Theory] - [CommonMemberData(nameof(CommonTestHelper.GetStringWithNullTheoryData))] + [MemberData(nameof(GetStringWithNullTheoryData))] public void FileDialogCustomPlace_Path_Set_GetReturnsExpected(string value) { var place = new FileDialogCustomPlace(Guid.NewGuid()) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs index 536bef25465..90f15df4a19 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs @@ -3,15 +3,25 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using WinForms.Common.Tests; using Xunit; namespace System.Windows.Forms.Tests { public class FileDialogCustomPlacesCollectionTests { + public static TheoryData GetStringWithNullTheoryData() + { + var data = new TheoryData + { + null, + string.Empty, + "reasonable" + }; + return data; + } + [Theory] - [CommonMemberData(nameof(CommonTestHelper.GetStringWithNullTheoryData))] + [MemberData(nameof(GetStringWithNullTheoryData))] public void FileDialogCustomPlacesCollection_Add_String_Success(string path) { var collection = new FileDialogCustomPlacesCollection @@ -23,8 +33,18 @@ public void FileDialogCustomPlacesCollection_Add_String_Success(string path) Assert.Same(path ?? string.Empty, place.Path); } + public static TheoryData GetGuidTheoryData() + { + var data = new TheoryData + { + Guid.Empty, + Guid.NewGuid() + }; + return data; + } + [Theory] - [CommonMemberData(nameof(CommonTestHelper.GetGuidTheoryData))] + [MemberData(nameof(GetGuidTheoryData))] public void FileDialogCustomPlacesCollection_Add_Guid_Success(Guid knownFolderGuid) { var collection = new FileDialogCustomPlacesCollection diff --git a/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj index 15d5a467ffa..62099193c84 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj +++ b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Common/tests/SystemEventsHelper.cs b/src/System.Windows.Forms/tests/TestUtilities/SystemEventsHelper.cs similarity index 99% rename from src/Common/tests/SystemEventsHelper.cs rename to src/System.Windows.Forms/tests/TestUtilities/SystemEventsHelper.cs index cd35e5a1ac9..86c29866c21 100644 --- a/src/Common/tests/SystemEventsHelper.cs +++ b/src/System.Windows.Forms/tests/TestUtilities/SystemEventsHelper.cs @@ -8,7 +8,7 @@ using Xunit; using static Interop.User32; -namespace WinForms.Common.Tests +namespace System { public static class SystemEventsHelper { diff --git a/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj b/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj index c5ed858cc56..f50c892432d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj +++ b/src/System.Windows.Forms/tests/UnitTests/System.Windows.Forms.Tests.csproj @@ -16,7 +16,7 @@ - + From 3dbb1585dcc3ab4cc05c746d8ccd55e796298fc1 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 27 May 2020 16:26:47 +1000 Subject: [PATCH 12/16] .. --- .../Interop/Oleaut32/IDispatchTests.cs | 21 +++------ .../Interop/Oleaut32/ITypeInfoTests.cs | 41 +++++++---------- .../UnitTests/Interop/Oleaut32/MockAxHost.cs | 44 +++++++++++++++++++ ...stem.Windows.Forms.Primitives.Tests.csproj | 1 + .../FileDialogCustomPlacesCollectionTests.cs | 2 +- 5 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs index fcf977f3903..19bf055d815 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs @@ -11,13 +11,13 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 { [Collection("Sequential")] - public class IDispatchTests + public partial class IDispatchTests { [WinFormsFact] public unsafe void IDispatch_GetIDsOfNames_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; Guid riid = Guid.Empty; @@ -36,7 +36,7 @@ public unsafe void IDispatch_GetIDsOfNames_Invoke_Success() public unsafe void IDispatch_GetTypeInfo_Invoke_Success() { using var image = new Bitmap(16, 16); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; @@ -50,7 +50,7 @@ public unsafe void IDispatch_GetTypeInfo_Invoke_Success() public unsafe void IDispatch_GetTypeInfoCount_Invoke_Success() { using var image = new Bitmap(16, 16); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; uint ctInfo = uint.MaxValue; @@ -63,7 +63,7 @@ public unsafe void IDispatch_GetTypeInfoCount_Invoke_Success() public unsafe void IDispatch_Invoke_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; Guid riid = Guid.Empty; @@ -82,17 +82,8 @@ public unsafe void IDispatch_Invoke_Invoke_Success() &argErr ); Assert.Equal(HRESULT.S_OK, hr); - Assert.Equal(16, GdiHelper.HimetricToPixelY((int)varResult[0])); + ////Assert.Equal(16, GdiHelper.HimetricToPixelY((int)varResult[0])); Assert.Equal(0u, argErr); } - - private class SubAxHost : AxHost - { - private SubAxHost(string clsidString) : base(clsidString) - { - } - - public new static IPictureDisp GetIPictureDispFromPicture(Image image) => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); - } } } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs index cea88ba56f9..8350403752d 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs @@ -18,7 +18,7 @@ public class ITypeInfoTests public unsafe void ITypeInfo_AddressOfMember_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -35,7 +35,7 @@ public unsafe void ITypeInfo_AddressOfMember_Invoke_Success() public unsafe void ITypeInfo_CreateInstance_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -53,7 +53,7 @@ public unsafe void ITypeInfo_CreateInstance_Invoke_Success() public unsafe void ITypeInfo_GetContainingTypeLib_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -79,7 +79,7 @@ public unsafe void ITypeInfo_GetContainingTypeLib_Invoke_Success() public unsafe void ITypeInfo_GetDllEntry_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -100,7 +100,7 @@ public unsafe void ITypeInfo_GetDllEntry_Invoke_Success() public unsafe void ITypeInfo_GetDocumentation_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -123,7 +123,7 @@ public unsafe void ITypeInfo_GetDocumentation_Invoke_Success() public unsafe void ITypeInfo_GetFuncDesc_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -160,7 +160,7 @@ public unsafe void ITypeInfo_GetFuncDesc_Invoke_Success() public unsafe void ITypeInfo_GetIDsOfNames_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -182,7 +182,7 @@ public unsafe void ITypeInfo_GetIDsOfNames_Invoke_Success() public unsafe void ITypeInfo_GetImplTypeFlags_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -199,7 +199,7 @@ public unsafe void ITypeInfo_GetImplTypeFlags_Invoke_Success() public unsafe void ITypeInfo_GetMops_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -216,7 +216,7 @@ public unsafe void ITypeInfo_GetMops_Invoke_Success() public unsafe void ITypeInfo_GetNames_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -241,7 +241,7 @@ public unsafe void ITypeInfo_GetNames_Invoke_Success() public unsafe void ITypeInfo_GetRefTypeInfo_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -264,7 +264,7 @@ public unsafe void ITypeInfo_GetRefTypeInfo_Invoke_Success() public unsafe void ITypeInfo_GetRefTypeOfImplType_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -281,7 +281,7 @@ public unsafe void ITypeInfo_GetRefTypeOfImplType_Invoke_Success() public unsafe void ITypeInfo_GetTypeAttr_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -323,7 +323,7 @@ public unsafe void ITypeInfo_GetTypeAttr_Invoke_Success() public unsafe void ITypeInfo_GetTypeComp_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -347,7 +347,7 @@ public unsafe void ITypeInfo_GetTypeComp_Invoke_Success() public unsafe void ITypeInfo_GetVarDesc_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -379,7 +379,7 @@ public unsafe void ITypeInfo_GetVarDesc_Invoke_Success() public unsafe void ITypeInfo_Invoke_Invoke_Success() { using var image = new Bitmap(16, 32); - IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); @@ -404,15 +404,6 @@ public unsafe void ITypeInfo_Invoke_Invoke_Success() Assert.Equal(0u, argErr); } - private class SubAxHost : AxHost - { - private SubAxHost(string clsidString) : base(clsidString) - { - } - - public new static IPictureDisp GetIPictureDispFromPicture(Image image) => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); - } - // ITypeInfo often requires manual RCW reference management. The native object may be free threaded // but when created on an STA thread it will be associated with that thread. If the native code keeps // reusing the same instance you can run into a condition where the GC cleans up the RCW from one STA diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs new file mode 100644 index 00000000000..dccf22d44e3 --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs @@ -0,0 +1,44 @@ +// 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.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using static Interop; +using static Interop.Ole32; + +namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 +{ + [ComVisible(true)] + [ClassInterface(ClassInterfaceType.AutoDispatch)] + internal class MockAxHost + { + private static Guid ipictureDisp_Guid = typeof(IPictureDisp).GUID; + + public MockAxHost(string clsidString) + { + } + + public static IPictureDisp GetIPictureDispFromPicture(Image image) + { + PICTDESC desc = GetPICTDESCFromPicture(image); + return (IPictureDisp)OleCreatePictureIndirect(ref desc, ref ipictureDisp_Guid, fOwn: BOOL.TRUE); + } + + private static PICTDESC GetPICTDESCFromPicture(Image image) + { + if (image is Bitmap bmp) + { + return PICTDESC.FromBitmap(bmp); + } + + if (image is Metafile mf) + { + return PICTDESC.FromMetafile(mf); + } + + throw new ArgumentException("AXUnknownImage", nameof(image)); + } + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj index 412b1f02061..2de347def05 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj @@ -3,6 +3,7 @@ System.Windows.Forms.Primitives.Tests true + $(NoWarn);618 diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs index 90f15df4a19..5887860b1b0 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/FileDialogCustomPlacesCollectionTests.cs @@ -42,7 +42,7 @@ public static TheoryData GetGuidTheoryData() }; return data; } - + [Theory] [MemberData(nameof(GetGuidTheoryData))] public void FileDialogCustomPlacesCollection_Add_Guid_Success(Guid knownFolderGuid) From 0151ba207877766ae4f1bf9cc65f75ea50e7d99d Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 27 May 2020 16:50:26 +1000 Subject: [PATCH 13/16] fix tests --- .../Interop/Oleaut32/IDispatchTests.cs | 8 ++--- .../Interop/Oleaut32/ITypeInfoTests.cs | 32 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs index 19bf055d815..eb6f6d1fd39 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs @@ -13,7 +13,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 [Collection("Sequential")] public partial class IDispatchTests { - [WinFormsFact] + [StaFact] public unsafe void IDispatch_GetIDsOfNames_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -32,7 +32,7 @@ public unsafe void IDispatch_GetIDsOfNames_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void IDispatch_GetTypeInfo_Invoke_Success() { using var image = new Bitmap(16, 16); @@ -46,7 +46,7 @@ public unsafe void IDispatch_GetTypeInfo_Invoke_Success() System.Runtime.InteropServices.Marshal.ReleaseComObject(typeInfo); } - [WinFormsFact] + [StaFact] public unsafe void IDispatch_GetTypeInfoCount_Invoke_Success() { using var image = new Bitmap(16, 16); @@ -59,7 +59,7 @@ public unsafe void IDispatch_GetTypeInfoCount_Invoke_Success() Assert.Equal(1u, ctInfo); } - [WinFormsFact] + [StaFact] public unsafe void IDispatch_Invoke_Invoke_Success() { using var image = new Bitmap(16, 32); diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs index 8350403752d..69f81f2ffca 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs @@ -14,7 +14,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 [Collection("Sequential")] public class ITypeInfoTests { - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_AddressOfMember_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -31,7 +31,7 @@ public unsafe void ITypeInfo_AddressOfMember_Invoke_Success() Assert.Equal(IntPtr.Zero, pv); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_CreateInstance_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -49,7 +49,7 @@ public unsafe void ITypeInfo_CreateInstance_Invoke_Success() Assert.Equal(IntPtr.Zero, pvObj); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetContainingTypeLib_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -75,7 +75,7 @@ public unsafe void ITypeInfo_GetContainingTypeLib_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetDllEntry_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -96,7 +96,7 @@ public unsafe void ITypeInfo_GetDllEntry_Invoke_Success() Assert.Equal(0u, wOrdinal); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetDocumentation_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -119,7 +119,7 @@ public unsafe void ITypeInfo_GetDocumentation_Invoke_Success() Assert.Empty(helpFile.String.ToString()); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetFuncDesc_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -156,7 +156,7 @@ public unsafe void ITypeInfo_GetFuncDesc_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetIDsOfNames_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -178,7 +178,7 @@ public unsafe void ITypeInfo_GetIDsOfNames_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetImplTypeFlags_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -195,7 +195,7 @@ public unsafe void ITypeInfo_GetImplTypeFlags_Invoke_Success() Assert.NotEqual(IMPLTYPEFLAG.FDEFAULT, implTypeFlags); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetMops_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -212,7 +212,7 @@ public unsafe void ITypeInfo_GetMops_Invoke_Success() Assert.Empty(mops.String.ToString()); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetNames_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -237,7 +237,7 @@ public unsafe void ITypeInfo_GetNames_Invoke_Success() rgszNames[1].Dispose(); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetRefTypeInfo_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -260,7 +260,7 @@ public unsafe void ITypeInfo_GetRefTypeInfo_Invoke_Success() Assert.NotNull(refTypeInfo); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetRefTypeOfImplType_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -277,7 +277,7 @@ public unsafe void ITypeInfo_GetRefTypeOfImplType_Invoke_Success() Assert.NotEqual(0u, refType); } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetTypeAttr_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -319,7 +319,7 @@ public unsafe void ITypeInfo_GetTypeAttr_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetTypeComp_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -343,7 +343,7 @@ public unsafe void ITypeInfo_GetTypeComp_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_GetVarDesc_Invoke_Success() { using var image = new Bitmap(16, 32); @@ -375,7 +375,7 @@ public unsafe void ITypeInfo_GetVarDesc_Invoke_Success() } } - [WinFormsFact] + [StaFact] public unsafe void ITypeInfo_Invoke_Invoke_Success() { using var image = new Bitmap(16, 32); From 30594a1f03fd3f748d56b095705a9b367028a4d9 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 3 Jun 2020 17:36:25 +1000 Subject: [PATCH 14/16] Fix IPictureTests tests --- .../tests/TestUtilities/GdiHelper.cs | 0 .../UnitTests/Interop/Mocks/MockAxHost.cs | 141 +++++++++++++ .../UnitTests/Interop/Mocks/MockCursor.cs | 53 +++++ .../UnitTests/Interop/Ole32/IPictureTests.cs | 186 +++++++++--------- .../Interop/Oleaut32/IDispatchTests.cs | 3 +- .../Interop/Oleaut32/ITypeInfoTests.cs | 1 + .../UnitTests/Interop/Oleaut32/MockAxHost.cs | 44 ----- ...stem.Windows.Forms.Primitives.Tests.csproj | 1 - .../System.Windows.Forms.TestUtilities.csproj | 1 + 9 files changed, 294 insertions(+), 136 deletions(-) rename src/{System.Windows.Forms => System.Windows.Forms.Primitives}/tests/TestUtilities/GdiHelper.cs (100%) create mode 100644 src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockAxHost.cs create mode 100644 src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockCursor.cs delete mode 100644 src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs diff --git a/src/System.Windows.Forms/tests/TestUtilities/GdiHelper.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/GdiHelper.cs similarity index 100% rename from src/System.Windows.Forms/tests/TestUtilities/GdiHelper.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/GdiHelper.cs diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockAxHost.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockAxHost.cs new file mode 100644 index 00000000000..d53644548e5 --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockAxHost.cs @@ -0,0 +1,141 @@ +// 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.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using static Interop; +using static Interop.Ole32; + +namespace System.Windows.Forms.Primitives.Tests.Interop.Mocks +{ + [ComVisible(true)] + [ClassInterface(ClassInterfaceType.AutoDispatch)] + internal class MockAxHost + { + private static Guid ipictureDisp_Guid = typeof(IPictureDisp).GUID; + private static Guid ipicture_Guid = typeof(IPicture).GUID; + + public MockAxHost(string clsidString) + { + } + + public static IPictureDisp GetIPictureDispFromPicture(Image image) + { + PICTDESC desc = GetPICTDESCFromPicture(image); + return (IPictureDisp)OleCreatePictureIndirect(ref desc, ref ipictureDisp_Guid, fOwn: BOOL.TRUE); + } + + public static IPicture GetIPictureFromCursor(IntPtr cursorHandle) + { + PICTDESC desc = PICTDESC.FromIcon(Icon.FromHandle(cursorHandle), copy: true); + return (IPicture)OleCreatePictureIndirect(ref desc, ref ipicture_Guid, fOwn: BOOL.TRUE); + } + + public static IPicture GetIPictureFromPicture(Image image) + { + PICTDESC desc = GetPICTDESCFromPicture(image); + return (IPicture)OleCreatePictureIndirect(ref desc, ref ipicture_Guid, fOwn: BOOL.TRUE); + } + + public static Image GetPictureFromIPicture(object picture) + { + int hPal = default; + IPicture pict = (IPicture)picture; + PICTYPE type = (PICTYPE)pict.Type; + if (type == PICTYPE.BITMAP) + { + try + { + hPal = pict.hPal; + } + catch (COMException) + { + } + } + + return GetPictureFromParams(pict.Handle, type, hPal, pict.Width, pict.Height); + } + + public static Image GetPictureFromIPictureDisp(object picture) + { + if (picture == null) + { + return null; + } + + int hPal = default; + IPictureDisp pict = (IPictureDisp)picture; + PICTYPE type = (PICTYPE)pict.Type; + if (type == PICTYPE.BITMAP) + { + try + { + hPal = pict.hPal; + } + catch (COMException) + { + } + } + + Image image = GetPictureFromParams(pict.Handle, type, hPal, pict.Width, pict.Height); + GC.KeepAlive(pict); + return image; + } + + private static PICTDESC GetPICTDESCFromPicture(Image image) + { + if (image is Bitmap bmp) + { + return PICTDESC.FromBitmap(bmp); + } + + if (image is Metafile mf) + { + return PICTDESC.FromMetafile(mf); + } + + throw new ArgumentException("AXUnknownImage", nameof(image)); + } + + private static Image GetPictureFromParams( + int handle, + PICTYPE type, + int paletteHandle, + int width, + int height) + { + switch (type) + { + case PICTYPE.ICON: + return (Image)Icon.FromHandle((IntPtr)handle).Clone(); + case PICTYPE.METAFILE: + WmfPlaceableFileHeader header = new WmfPlaceableFileHeader + { + BboxRight = (short)width, + BboxBottom = (short)height + }; + + using (var metafile = new Metafile((IntPtr)handle, header, deleteWmf: false)) + { + return (Image)metafile.Clone(); + } + case PICTYPE.ENHMETAFILE: + using (var metafile = new Metafile((IntPtr)handle, deleteEmf: false)) + { + return (Image)metafile.Clone(); + } + case PICTYPE.BITMAP: + return Image.FromHbitmap((IntPtr)handle, (IntPtr)paletteHandle); + case PICTYPE.NONE: + // MSDN says this should not be a valid value, but comctl32 returns it... + return null; + case PICTYPE.UNINITIALIZED: + return null; + default: + throw new ArgumentException("AXUnknownImage", nameof(type)); + } + } + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockCursor.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockCursor.cs new file mode 100644 index 00000000000..8c70dddbfca --- /dev/null +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Mocks/MockCursor.cs @@ -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. +// See the LICENSE file in the project root for more information. + +using System.Drawing; +using static Interop.User32; + +namespace System.Windows.Forms.Primitives.Tests.Interop.Mocks +{ + public class MockCursor : IDisposable + { + private IntPtr _handle = IntPtr.Zero; // handle to loaded image + private bool _ownHandle = true; + private readonly int _resourceId = 0; + + public MockCursor(int nResourceId) + { + // We don't delete stock cursors. + _ownHandle = false; + _resourceId = nResourceId; + _handle = LoadCursorW(IntPtr.Zero, (IntPtr)nResourceId); + } + + public void Dispose() + { + if (_handle != IntPtr.Zero) + { + if (_ownHandle) + { + DestroyCursor(_handle); + } + _handle = IntPtr.Zero; + } + } + + public IntPtr Handle + { + get + { + if (_handle == IntPtr.Zero) + { + throw new ObjectDisposedException(nameof(MockCursor)); + } + return _handle; + } + } + + public Size Size + { + get => new Size(GetSystemMetrics(SystemMetric.SM_CXCURSOR), GetSystemMetrics(SystemMetric.SM_CYCURSOR)); + } + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs index fb5096e9cd1..885d571535d 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs @@ -2,93 +2,99 @@ // 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.Drawing; -// using Xunit; -// using static Interop.Ole32; - -// namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32 -// { -// public class IPictureTests -// { -// [Fact] -// public void GetIPictureFromCursor() -// { -// Cursor arrow = Cursors.Arrow; -// IPicture picture = AxHostAccess.GetIPictureFromCursor(arrow); -// Assert.NotNull(picture); -// Assert.Equal(PICTYPE.ICON, (PICTYPE)picture.Type); - -// Assert.Equal(arrow.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); -// Assert.Equal(arrow.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); -// } - -// [Fact] -// public void GetIPictureFromImage() -// { -// using Icon icon = Icon.FromHandle(Cursors.Arrow.Handle); -// using Bitmap bitmap = icon.ToBitmap(); -// IPicture picture = AxHostAccess.GetIPictureFromPicture(bitmap); -// Assert.NotNull(picture); -// Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); - -// Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); -// Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); -// } - -// [Fact] -// public void GetIPictureDispFromImage() -// { -// using Icon icon = SystemIcons.Question; -// using Bitmap bitmap = icon.ToBitmap(); -// IPictureDisp picture = AxHostAccess.GetIPictureDispFromPicture(bitmap); -// Assert.NotNull(picture); -// Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); - -// Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); -// Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); -// } - -// [Fact] -// public void GetPictureFromIPicture() -// { -// using Icon icon = SystemIcons.Exclamation; -// using Bitmap bitmap = icon.ToBitmap(); -// IPicture picture = AxHostAccess.GetIPictureFromPicture(bitmap); -// Assert.NotNull(picture); -// using Image image = AxHostAccess.GetPictureFromIPicture(picture); -// Assert.NotNull(image); -// Assert.Equal(bitmap.Size, image.Size); -// } - -// [Fact] -// public void GetPictureFromIPictureDisp() -// { -// using Bitmap bitmap = new Bitmap(100, 200); -// IPictureDisp picture = AxHostAccess.GetIPictureDispFromPicture(bitmap); -// Assert.NotNull(picture); -// using Image image = AxHostAccess.GetPictureFromIPictureDisp(picture); -// Assert.NotNull(image); -// Assert.Equal(bitmap.Size, image.Size); -// } - -// internal class AxHostAccess : AxHost -// { -// private AxHostAccess() : base(string.Empty) { } - -// internal new static IPicture GetIPictureFromCursor(Cursor cursor) -// => (IPicture)AxHost.GetIPictureFromCursor(cursor); - -// internal new static IPicture GetIPictureFromPicture(Image image) -// => (IPicture)AxHost.GetIPictureFromPicture(image); - -// internal new static IPictureDisp GetIPictureDispFromPicture(Image image) -// => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); - -// internal static Image GetPictureFromIPicture(IPicture picture) -// => GetPictureFromIPicture((object)picture); - -// internal static Image GetPictureFromIPictureDisp(IPictureDisp picture) -// => GetPictureFromIPictureDisp((object)picture); -// } -// } -// } +using System.Drawing; +using Xunit; +using System.Windows.Forms.Primitives.Tests.Interop.Mocks; +using static Interop.Ole32; +using static Interop.User32; + +namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32 +{ + + [Collection("Sequential")] + public class IPictureTests + { + [Fact] + public void GetIPictureFromCursor() + { + using MockCursor arrow = new MockCursor(CursorResourceId.IDC_ARROW); + + IPicture picture = MockAxHost.GetIPictureFromCursor(arrow.Handle); + Assert.NotNull(picture); + Assert.Equal(PICTYPE.ICON, (PICTYPE)picture.Type); + + Assert.Equal(arrow.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); + Assert.Equal(arrow.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); + } + + [Fact] + public void GetIPictureFromImage() + { + using MockCursor arrow = new MockCursor(CursorResourceId.IDC_ARROW); + using Icon icon = Icon.FromHandle(arrow.Handle); + using Bitmap bitmap = icon.ToBitmap(); + IPicture picture = MockAxHost.GetIPictureFromPicture(bitmap); + Assert.NotNull(picture); + Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); + + Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); + Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); + } + + [Fact] + public void GetIPictureDispFromImage() + { + using Icon icon = SystemIcons.Question; + using Bitmap bitmap = icon.ToBitmap(); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(bitmap); + Assert.NotNull(picture); + Assert.Equal(PICTYPE.BITMAP, (PICTYPE)picture.Type); + + Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(picture.Height)); + Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); + } + + [Fact] + public void GetPictureFromIPicture() + { + using Icon icon = SystemIcons.Exclamation; + using Bitmap bitmap = icon.ToBitmap(); + IPicture picture = MockAxHost.GetIPictureFromPicture(bitmap); + Assert.NotNull(picture); + using Image image = MockAxHost.GetPictureFromIPicture(picture); + Assert.NotNull(image); + Assert.Equal(bitmap.Size, image.Size); + } + + [Fact] + public void GetPictureFromIPictureDisp() + { + using Bitmap bitmap = new Bitmap(100, 200); + IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(bitmap); + Assert.NotNull(picture); + using Image image = MockAxHost.GetPictureFromIPictureDisp(picture); + Assert.NotNull(image); + Assert.Equal(bitmap.Size, image.Size); + } + + //internal class MockAxHost : AxHost + //{ + // private MockAxHost() : base(string.Empty) { } + + // internal new static IPicture GetIPictureFromCursor(Cursor cursor) + // => (IPicture)AxHost.GetIPictureFromCursor(cursor); + + // internal new static IPicture GetIPictureFromPicture(Image image) + // => (IPicture)AxHost.GetIPictureFromPicture(image); + + // internal new static IPictureDisp GetIPictureDispFromPicture(Image image) + // => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); + + // internal static Image GetPictureFromIPicture(IPicture picture) + // => GetPictureFromIPicture((object)picture); + + // internal static Image GetPictureFromIPictureDisp(IPictureDisp picture) + // => GetPictureFromIPictureDisp((object)picture); + //} + } +} diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs index eb6f6d1fd39..272a2d65afb 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/IDispatchTests.cs @@ -4,6 +4,7 @@ using System.Drawing; using Xunit; +using System.Windows.Forms.Primitives.Tests.Interop.Mocks; using static Interop; using static Interop.Ole32; using static Interop.Oleaut32; @@ -82,7 +83,7 @@ public unsafe void IDispatch_Invoke_Invoke_Success() &argErr ); Assert.Equal(HRESULT.S_OK, hr); - ////Assert.Equal(16, GdiHelper.HimetricToPixelY((int)varResult[0])); + Assert.Equal(16, GdiHelper.HimetricToPixelY((int)varResult[0])); Assert.Equal(0u, argErr); } } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs index 69f81f2ffca..b9d30cc6e2b 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.Runtime.InteropServices; +using System.Windows.Forms.Primitives.Tests.Interop.Mocks; using Xunit; using static Interop; using static Interop.Ole32; diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs deleted file mode 100644 index dccf22d44e3..00000000000 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/MockAxHost.cs +++ /dev/null @@ -1,44 +0,0 @@ -// 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.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; -using static Interop; -using static Interop.Ole32; - -namespace System.Windows.Forms.Primitives.Tests.Interop.Oleaut32 -{ - [ComVisible(true)] - [ClassInterface(ClassInterfaceType.AutoDispatch)] - internal class MockAxHost - { - private static Guid ipictureDisp_Guid = typeof(IPictureDisp).GUID; - - public MockAxHost(string clsidString) - { - } - - public static IPictureDisp GetIPictureDispFromPicture(Image image) - { - PICTDESC desc = GetPICTDESCFromPicture(image); - return (IPictureDisp)OleCreatePictureIndirect(ref desc, ref ipictureDisp_Guid, fOwn: BOOL.TRUE); - } - - private static PICTDESC GetPICTDESCFromPicture(Image image) - { - if (image is Bitmap bmp) - { - return PICTDESC.FromBitmap(bmp); - } - - if (image is Metafile mf) - { - return PICTDESC.FromMetafile(mf); - } - - throw new ArgumentException("AXUnknownImage", nameof(image)); - } - } -} diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj index 2de347def05..3ea85b8a5ad 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System.Windows.Forms.Primitives.Tests.csproj @@ -13,7 +13,6 @@ - diff --git a/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj index 62099193c84..67f5df65580 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj +++ b/src/System.Windows.Forms/tests/TestUtilities/System.Windows.Forms.TestUtilities.csproj @@ -16,6 +16,7 @@ + From 37eaa080d2c888366b89ef829993b0fdb30c1a65 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 3 Jun 2020 17:43:42 +1000 Subject: [PATCH 15/16] fixup! Fix IPictureTests tests --- .../UnitTests/Interop/Ole32/IPictureTests.cs | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs index 885d571535d..ff52cfe16e3 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs @@ -10,7 +10,6 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32 { - [Collection("Sequential")] public class IPictureTests { @@ -76,25 +75,5 @@ public void GetPictureFromIPictureDisp() Assert.NotNull(image); Assert.Equal(bitmap.Size, image.Size); } - - //internal class MockAxHost : AxHost - //{ - // private MockAxHost() : base(string.Empty) { } - - // internal new static IPicture GetIPictureFromCursor(Cursor cursor) - // => (IPicture)AxHost.GetIPictureFromCursor(cursor); - - // internal new static IPicture GetIPictureFromPicture(Image image) - // => (IPicture)AxHost.GetIPictureFromPicture(image); - - // internal new static IPictureDisp GetIPictureDispFromPicture(Image image) - // => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image); - - // internal static Image GetPictureFromIPicture(IPicture picture) - // => GetPictureFromIPicture((object)picture); - - // internal static Image GetPictureFromIPictureDisp(IPictureDisp picture) - // => GetPictureFromIPictureDisp((object)picture); - //} } } From 0791c3c3a6be11a3abd8eca1d85fa1fc386e8faa Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 3 Jun 2020 20:54:02 +1000 Subject: [PATCH 16/16] Switch to StaFact --- .../tests/UnitTests/Interop/Ole32/IPictureTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs index ff52cfe16e3..98ccce1befd 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs @@ -13,7 +13,7 @@ namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32 [Collection("Sequential")] public class IPictureTests { - [Fact] + [StaFact] public void GetIPictureFromCursor() { using MockCursor arrow = new MockCursor(CursorResourceId.IDC_ARROW); @@ -26,7 +26,7 @@ public void GetIPictureFromCursor() Assert.Equal(arrow.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); } - [Fact] + [StaFact] public void GetIPictureFromImage() { using MockCursor arrow = new MockCursor(CursorResourceId.IDC_ARROW); @@ -40,7 +40,7 @@ public void GetIPictureFromImage() Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); } - [Fact] + [StaFact] public void GetIPictureDispFromImage() { using Icon icon = SystemIcons.Question; @@ -53,7 +53,7 @@ public void GetIPictureDispFromImage() Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(picture.Width)); } - [Fact] + [StaFact] public void GetPictureFromIPicture() { using Icon icon = SystemIcons.Exclamation; @@ -65,7 +65,7 @@ public void GetPictureFromIPicture() Assert.Equal(bitmap.Size, image.Size); } - [Fact] + [StaFact] public void GetPictureFromIPictureDisp() { using Bitmap bitmap = new Bitmap(100, 200);