public void WindowResizingEventProducerCallbackTest() { /* PRECONDITIONS */ Debug.Assert(windowManagementModule != null); Debug.Assert(windowResizingEventProducer != null); Debug.Assert(hookNativeMethods != null); Debug.Assert(hookNativeMethods.Mock != null); /* GIVEN */ var callback = GetCallback(); nativeWindowManagement.GetProcessName(); nativeWindowManagement.GetTitle(); nativeWindowManagement.IsRectSizeNotEqual(); nativeWindowManagement.GetWindowRect(); nativeWindowManagement.GetWidthAndHeight(); using var consumedEvent = new CountdownEvent(1); using var didStartConsumingEvent = new ManualResetEvent(false); var thread = new Thread(async() => { await foreach (var @event in Await( windowResizingEventProducer.GetEvents(), didStartConsumingEvent)) { if (!(@event.Title.Equals("Title") && @event.ProcessName.Equals("ProcessName") && @event.OldSize.Equals(new Size(1, 1)) && @event.NewSize.Equals(new Size(2, 2)))) { continue; } consumedEvent.Signal(); } }); thread.Start(); Assert.IsTrue(didStartConsumingEvent.WaitOne(MaxWaitTime)); callback(new GlobalHook.HookMessage { Type = (uint)GlobalHook.MessageType.WM_ENTERSIZEMOVE, Hwnd = (IntPtr)1 }); callback(new GlobalHook.HookMessage { Type = (uint)GlobalHook.MessageType.WM_EXITSIZEMOVE, Hwnd = (IntPtr)1 }); /* THEN */ Assert.IsTrue(consumedEvent.Wait(MaxWaitTime), "Did not find all matching window resizing event in time."); windowManagementModule.IsActive = false; windowManagementModule.Initialize(false); }
public void WindowStateChangedEventProducerCallbackTest() { /* PRECONDITIONS */ Debug.Assert(windowManagementModule != null); Debug.Assert(windowStateChangedEventProducer != null); Debug.Assert(hookNativeMethods != null); Debug.Assert(hookNativeMethods.Mock != null); Debug.Assert(nativeWindowManagement != null); /* GIVEN */ var callback = GetCallback(); nativeWindowManagement.GetProcessName(); nativeWindowManagement.GetTitle(); nativeWindowManagement.IsRectSizeNotEqual(); nativeWindowManagement.GetWindowRect(); GlobalHook.HookMessage[] hookMessages = { new GlobalHook.HookMessage { Type = (uint)GlobalHook.MessageType.WM_SIZE, wParam = (IntPtr)WindowState.Maximized, Hwnd = (IntPtr)1 }, new GlobalHook.HookMessage { Type = (uint)GlobalHook.MessageType.WM_SIZE, wParam = (IntPtr)WindowState.Minimized, Hwnd = (IntPtr)1 }, new GlobalHook.HookMessage { Type = (uint)GlobalHook.MessageType.WM_ENTERSIZEMOVE, Hwnd = (IntPtr)1 }, new GlobalHook.HookMessage { Type = (uint)GlobalHook.MessageType.WM_EXITSIZEMOVE, Hwnd = (IntPtr)1 } }; WindowStateChangedEvent[] expectedEvents = { new WindowStateChangedEvent { ProcessName = "ProcessName", Title = "Title", WindowState = WindowState.Maximized }, new WindowStateChangedEvent { ProcessName = "ProcessName", Title = "Title", WindowState = WindowState.Minimized }, new WindowStateChangedEvent { ProcessName = "ProcessName", Title = "Title", WindowState = WindowState.Normal } }; Assert.IsTrue(hookMessages.Length == expectedEvents.Length + 1); /* WHEN */ using var consumedEvent = new CountdownEvent(expectedEvents.Length); Assert.IsTrue(consumedEvent.CurrentCount == expectedEvents.Length); using var didStartConsumingEvent = new ManualResetEvent(false); var thread = new Thread(async() => { await foreach (var @event in Await( windowStateChangedEventProducer.GetEvents(), didStartConsumingEvent)) { if (!IsWindowStateChangedEventFound(@event, expectedEvents)) { continue; } consumedEvent.Signal(); } }); thread.Start(); Assert.IsTrue(didStartConsumingEvent.WaitOne(MaxWaitTime)); foreach (var msg in hookMessages) { callback(msg); } /* THEN */ Assert.IsTrue(consumedEvent.Wait(MaxWaitTime), "Did not find all matching window state changed event in time."); windowStateChangedEventProducer.StopCapture(); windowManagementModule.Initialize(false); }