-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add initial VB6 tests #8253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add initial VB6 tests #8253
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
....Windows.Forms.Primitives/tests/TestUtilities/Windows/Win32/System/Com/ComClassFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // 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.ComponentModel; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Windows.Win32.System.Com; | ||
|
|
||
| /// <summary> | ||
| /// Wraps an <see cref="IClassFactory"/> from a dynamically loaded assembly. | ||
| /// </summary> | ||
| internal unsafe class ComClassFactory : IDisposable | ||
| { | ||
| private readonly string _filePath; | ||
| public Guid ClassId { get; } | ||
| private readonly HINSTANCE _instance; | ||
| private AgileComPointer<IClassFactory> _classFactory; | ||
|
|
||
| private const string ExportMethodName = "DllGetClassObject"; | ||
|
|
||
| public ComClassFactory( | ||
| string filePath, | ||
| Guid classId) | ||
| { | ||
| HRESULT result = PInvoke.OleInitialize(pvReserved: (void*)null); | ||
|
|
||
| _filePath = filePath; | ||
| ClassId = classId; | ||
| _instance = PInvoke.LoadLibraryEx(filePath, HANDLE.Null, default); | ||
| if (_instance.IsNull) | ||
| { | ||
| throw new Win32Exception(); | ||
| } | ||
|
|
||
| string name = PInvoke.GetModuleFileNameLongPath(_instance); | ||
|
|
||
| // Dynamically get the class factory method. | ||
|
|
||
| // HRESULT DllGetClassObject( | ||
| // [in] REFCLSID rclsid, | ||
| // [in] REFIID riid, | ||
| // [out] LPVOID* ppv | ||
| // ); | ||
|
|
||
| FARPROC proc = PInvoke.GetProcAddress(_instance, ExportMethodName); | ||
| IClassFactory* classFactory; | ||
| ((delegate* unmanaged<Guid*, Guid*, void**, HRESULT>)proc.Value)( | ||
| &classId, IID.Get<IClassFactory>(), | ||
| (void**)&classFactory).ThrowOnFailure(); | ||
| _classFactory = new(classFactory); | ||
| } | ||
|
|
||
| internal HRESULT CreateInstance(out IUnknown* unknown) | ||
| { | ||
| unknown = default; | ||
| fixed (IUnknown** u = &unknown) | ||
| { | ||
| using var factory = _classFactory.GetInterface(); | ||
| return factory.Value->CreateInstance(null, IID.Get<IUnknown>(), (void**)u); | ||
| } | ||
| } | ||
|
|
||
| internal HRESULT CreateInstance(out object unknown) | ||
| { | ||
| HRESULT result = CreateInstance(out IUnknown* punk); | ||
| unknown = result.Failed || punk is null ? null : Marshal.GetObjectForIUnknown((nint)punk); | ||
| return result; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _classFactory.Dispose(); | ||
| PInvoke.FreeLibrary(_instance); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHost.VisualBasic6Tests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // 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.ComponentModel; | ||
| using System.Runtime.InteropServices; | ||
| using System.Windows.Forms.Tests.TestResources; | ||
| using Xunit; | ||
|
|
||
| namespace System.Windows.Forms.Tests | ||
| { | ||
| public class AxHostVisualBasic6Tests | ||
| { | ||
| [WinFormsFact] | ||
| public void AxHost_SimpleControl_Create() | ||
| { | ||
| if (RuntimeInformation.ProcessArchitecture != Architecture.X86) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| using Form form = new(); | ||
| form.Shown += (object sender, EventArgs e) => form.Close(); | ||
| using DynamicAxHost control = new(ComClasses.VisualBasicSimpleControl); | ||
| ((ISupportInitialize)control).BeginInit(); | ||
| form.Controls.Add(control); | ||
| ((ISupportInitialize)control).EndInit(); | ||
| form.ShowDialog(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DynamicAxHost.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // 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 Windows.Win32.System.Com; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace System.Windows.Forms.Tests | ||
| { | ||
| /// <summary> | ||
| /// Custom <see cref="AxHost"/> that directly uses a <see cref="ComClassFactory"/>. | ||
| /// </summary> | ||
| public unsafe class DynamicAxHost : AxHost | ||
| { | ||
| private readonly ComClassFactory _factory; | ||
|
|
||
| internal DynamicAxHost(ComClassFactory factory) : base(factory.ClassId.ToString("D"), 0) | ||
| { | ||
| _factory = factory; | ||
| } | ||
|
|
||
| protected override object CreateInstanceCore(Guid clsid) | ||
| { | ||
| Debug.Assert(clsid == _factory.ClassId); | ||
| _factory.CreateInstance(out object unknown).ThrowOnFailure(); | ||
| return unknown; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason to run this as a unit test and not as UI integration test? The latter are run serially.