Skip to content

Commit

Permalink
Add some StdComponentCategoriesManager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyKuhne committed Sep 20, 2023
1 parent b2c883d commit 1df1f32
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/samples/ActiveX/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Drawing;
using Windows;
using Windows.Win32.System.Com;

namespace ActiveXSample;

Expand Down Expand Up @@ -44,10 +45,8 @@ public MainWindow(string title) : base(

private class MediaPlayer : ActiveXControl
{
private static readonly Guid s_mediaPlayerClassId = new("6BF52A52-394A-11d3-B153-00C04F79FAA6");

public MediaPlayer(Rectangle bounds, Window parentWindow, nint parameters = 0)
: base(s_mediaPlayerClassId, bounds, parentWindow, parameters)
: base(CLSID.WindowsMediaPlayer, bounds, parentWindow, parameters)
{
}

Expand Down
2 changes: 2 additions & 0 deletions src/thirtytwo/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ GetThreadDpiAwarenessContext
GetThreadLocale
GetUpdatedClipboardFormats
GetUpdateRgn
GetUserDefaultLCID
GetWindowRect
GetWindowRgn
GetWindowText
Expand All @@ -133,6 +134,7 @@ IAccessible
IAccessibleEx
IAccIdentity
IAgileObject
ICatInformation
IClassFactory2
IConnectionPoint
IConnectionPointContainer
Expand Down
14 changes: 14 additions & 0 deletions src/thirtytwo/Win32/System/Com/CATID.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Windows.Win32.System.Com;

public static class CATID
{
/// <summary>
/// ActiveX control category id.
/// </summary>
public static Guid Control { get; }
// 40fc6ed4-2438-11cf-a3db-080036f12502
= new(0x40fc6ed4, 0x2438, 0x11cf, 0xa3, 0xdb, 0x08, 0x00, 0x36, 0xf1, 0x25, 0x02);
}
26 changes: 16 additions & 10 deletions src/thirtytwo/Win32/System/Com/CLSID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@

namespace Windows.Win32.System.Com;

internal static class CLSID
public static class CLSID
{
// 00BB2763-6A77-11D0-A535-00C04FD7D062
internal static Guid AutoComplete = new(0x00BB2763, 0x6A77, 0x11D0, 0xA5, 0x35, 0x00, 0xC0, 0x4F, 0xD7, 0xD0, 0x62);
// 00bb2763-6a77-11d0-a535-00c04fd7d062
public static Guid AutoComplete { get; } = new(0x00bb2763, 0x6a77, 0x11d0, 0xa5, 0x35, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62);

// 4657278A-411B-11D2-839A-00C04FD918D0
internal static Guid DragDropHelper = new(0x4657278A, 0x411B, 0x11D2, 0x83, 0x9A, 0x0, 0xC0, 0x4F, 0xD9, 0x18, 0xD0);
// 4657278a-411b-11d2-839a-00c04fd918d0
public static Guid DragDropHelper { get; } = new(0x4657278a, 0x411b, 0x11d2, 0x83, 0x9a, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0xd0);

// C0B4E2F3-BA21-4773-8DBA-335EC946EB8B
internal static Guid FileSaveDialog = new(0xC0B4E2F3, 0xBA21, 0x4773, 0x8D, 0xBA, 0x33, 0x5E, 0xC9, 0x46, 0xEB, 0x8B);
// c0b4e2f3-ba21-4773-8dba-335ec946eb8b
public static Guid FileSaveDialog { get; } = new(0xc0b4e2f3, 0xba21, 0x4773, 0x8d, 0xba, 0x33, 0x5e, 0xc9, 0x46, 0xeb, 0x8b);

// DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7
internal static Guid FileOpenDialog = new(0xDC1C5A9C, 0xE88A, 0x4DDE, 0xA5, 0xA1, 0x60, 0xF8, 0x2A, 0x20, 0xAE, 0xF7);
// dc1c5a9c-e88a-4dde-a5a1-60f82a20aef7
public static Guid FileOpenDialog { get; } = new(0xdc1c5a9c, 0xe88a, 0x4dde, 0xa5, 0xa1, 0x60, 0xf8, 0x2a, 0x20, 0xae, 0xf7);

// 00000323-0000-0000-c000-000000000046
internal static Guid StdGlobalInterfaceTable = new(0x00000323, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
public static Guid StdGlobalInterfaceTable { get; } = new(0x00000323, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

// 0002e005-0000-0000-c000-000000000046
public static Guid StdComponentCategoriesManager { get; } = new(0x0002e005, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

// 6bf52a52-394a-11d3-b153-00c04f79faa6
public static Guid WindowsMediaPlayer { get; } = new(0x6bf52a52, 0x394a, 0x11d3, 0xb1, 0x53, 0x00, 0xc0, 0x4f, 0x79, 0xfa, 0xa6);
}
4 changes: 2 additions & 2 deletions src/thirtytwo/Win32/System/Com/GlobalInterfaceTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ internal static unsafe class GlobalInterfaceTable

static GlobalInterfaceTable()
{
Guid clsid = CLSID.StdGlobalInterfaceTable;
fixed (IGlobalInterfaceTable** git = &s_globalInterfaceTable)
fixed (Guid* g = &CLSID.StdGlobalInterfaceTable)
{
Interop.CoCreateInstance(
g,
&clsid,
pUnkOuter: null,
CLSCTX.CLSCTX_INPROC_SERVER,
IID.Get<IGlobalInterfaceTable>(),
Expand Down
5 changes: 2 additions & 3 deletions src/thirtytwo_tests/Controls/ActiveXControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Windows;
using Windows.Win32.System.Com;

namespace Tests.Windows.Controls;

public class ActiveXControlTests
{
private static readonly Guid s_mediaPlayerClassId = new("6BF52A52-394A-11d3-B153-00C04F79FAA6");

[StaFact]
public void ActiveXControl_MediaPlayer_Create()
{
using Window container = new(Window.DefaultBounds);
using ActiveXControl control = new(s_mediaPlayerClassId, Window.DefaultBounds, container);
using ActiveXControl control = new(CLSID.WindowsMediaPlayer, Window.DefaultBounds, container);
container.AddLayoutHandler(Layout.Fill(control));
}
}
4 changes: 1 addition & 3 deletions src/thirtytwo_tests/Win32/ComHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ namespace Tests.Windows.Win32;

public unsafe class ComHelpersTests
{
private static readonly Guid s_mediaPlayerClassId = new("6BF52A52-394A-11d3-B153-00C04F79FAA6");

[StaFact]
public void CreateComClass_MediaPlayer()
{
using ComScope<IUnknown> mediaPlayer = new(ComHelpers.CreateComClass(s_mediaPlayerClassId));
using ComScope<IUnknown> mediaPlayer = new(ComHelpers.CreateComClass(CLSID.WindowsMediaPlayer));

using ComScope<IDispatch> dispatch = mediaPlayer.TryQueryInterface<IDispatch>(out HRESULT hr);
hr.Succeeded.Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ namespace Tests.Windows.Win32.System.Com;

public unsafe class ComTypeDescriptorTests
{
private static readonly Guid s_mediaPlayerClassId = new("6BF52A52-394A-11d3-B153-00C04F79FAA6");

[StaFact]
public void ComTypeDescriptor_ClassName_MediaPlayer()
{
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(s_mediaPlayerClassId), takeOwnership: true);
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(CLSID.WindowsMediaPlayer), takeOwnership: true);
ComTypeDescriptor comDescriptor = new(unknown);
ICustomTypeDescriptor descriptor = comDescriptor;
string? className = descriptor.GetClassName();
Expand All @@ -24,7 +22,7 @@ public void ComTypeDescriptor_ClassName_MediaPlayer()
[StaFact]
public void ComTypeDescriptor_ComponentName_MediaPlayer()
{
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(s_mediaPlayerClassId), takeOwnership: true);
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(CLSID.WindowsMediaPlayer), takeOwnership: true);
ComTypeDescriptor comDescriptor = new(unknown);
ICustomTypeDescriptor descriptor = comDescriptor;
string? className = descriptor.GetComponentName();
Expand All @@ -34,7 +32,7 @@ public void ComTypeDescriptor_ComponentName_MediaPlayer()
[StaFact]
public void ComTypeDescriptor_GetProperties_MediaPlayer()
{
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(s_mediaPlayerClassId), takeOwnership: true);
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(CLSID.WindowsMediaPlayer), takeOwnership: true);
ComTypeDescriptor comDescriptor = new(unknown);
ICustomTypeDescriptor descriptor = comDescriptor;
var properties = descriptor.GetProperties();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;

namespace Tests.Windows.Win32.System.Com;

public unsafe class ComponentCategoriesManagerTests
{
[StaFact]
public void EnumerateCategories()
{
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(CLSID.StdComponentCategoriesManager), takeOwnership: true);
using var categoriesInfo = unknown.TryGetInterface<ICatInformation>(out HRESULT hr);

using ComScope<IEnumCATEGORYINFO> enumCategories = new(null);
hr = categoriesInfo.Value->EnumCategories(Interop.GetUserDefaultLCID(), enumCategories);

Dictionary<Guid, string> categories = new();
CATEGORYINFO categoryInfo = default;
uint fetched = 0;
while (enumCategories.Value->Next(1, &categoryInfo, &fetched).Succeeded && fetched == 1)
{
categories.Add(categoryInfo.catid, categoryInfo.szDescription.ToString());
}

categories.Should().Contain(new KeyValuePair<Guid, string>(CATID.Control, "Controls"));
}

[StaFact]
public void EnumerateActiveXClasses()
{
using AgileComPointer<IUnknown> unknown = new(ComHelpers.CreateComClass(CLSID.StdComponentCategoriesManager), takeOwnership: true);
using var categoriesInfo = unknown.TryGetInterface<ICatInformation>(out HRESULT hr);

using ComScope<IEnumGUID> enumGuids = new(null);
Guid control = CATID.Control;
hr = categoriesInfo.Value->EnumClassesOfCategories(1, &control, 0, null, enumGuids);
hr.Succeeded.Should().BeTrue();

List<Guid> classGuids = new();
Guid guid = default;
uint fetched = 0;
while (enumGuids.Value->Next(1, &guid, &fetched).Succeeded && fetched == 1)
{
classGuids.Add(guid);
}

classGuids.Should().Contain(CLSID.WindowsMediaPlayer);
}
}

0 comments on commit 1df1f32

Please sign in to comment.