Skip to content

Commit

Permalink
Updated testing for User32 wrapper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dahall committed Apr 10, 2023
1 parent 0493dbd commit f4e7852
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion UnitTests/PInvoke/User32/WrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
using Vanara.InteropServices;
using static Vanara.PInvoke.Kernel32;
using static Vanara.PInvoke.User32;
Expand All @@ -20,7 +21,7 @@ public void WindowClassCtorTest()
WindowClass wc = null;

Assert.DoesNotThrow(() => wc = new());
Assert.AreEqual(wc.wc.hInstance, (HINSTANCE)GetModuleHandle());
Assert.AreEqual(wc.wc.hInstance, HINSTANCE.NULL);
Assert.True(wc.Unregister());

Assert.DoesNotThrow(() => wc = new("MyCustomName"));
Expand All @@ -29,11 +30,25 @@ public void WindowClassCtorTest()

Assert.DoesNotThrow(() => wc = WindowClass.MakeVisibleWindowClass("MyWindowClass", DefWindowProc));
Assert.AreEqual(wc.ClassName, "MyWindowClass");
Assert.AreEqual(wc.wc.hInstance, (HINSTANCE)GetModuleHandle());
Assert.AreNotEqual(wc.wc.hIcon, HICON.NULL);
Assert.AreNotEqual(wc.wc.hCursor, HCURSOR.NULL);
Assert.AreNotEqual(wc.wc.hbrBackground, HBRUSH.NULL);
}

[Test]
public void WindowClassCreateWinTest()
{
var _wndProc = new WindowProc(WndProc);
var _gcHandle = GCHandle.Alloc(_wndProc);
var windowClass = new WindowClass(null, HINSTANCE.NULL, _wndProc, hbrBkgd: HBRUSH.NULL);
var exStyles = WindowStylesEx.WS_EX_LAYERED | WindowStylesEx.WS_EX_NOACTIVATE | WindowStylesEx.WS_EX_TRANSPARENT | WindowStylesEx.WS_EX_NOREDIRECTIONBITMAP;
var styles = WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_POPUP | WindowStyles.WS_CLIPSIBLINGS;
Assert.That(CreateWindowEx(exStyles, windowClass.ClassName, "Test Window", styles), ResultIs.ValidHandle);
}

private static IntPtr WndProc(HWND hwnd, uint uMsg, IntPtr wParam, IntPtr lParam) => DefWindowProc(hwnd, uMsg, wParam, lParam);

[Test]
public void WindowClassCreateTest()
{
Expand Down

0 comments on commit f4e7852

Please sign in to comment.