示例#1
0
        public void ClipboardCopyEventProducerWinMessageSinkTest()
        {
            /* PRECONDITIONS */
            Debug.Assert(clipboardModule != null);
            Debug.Assert(clipboardCopyEventProducer != null);
            Debug.Assert(hookNativeMethods != null);
            Debug.Assert(nativeClipboard != null);
            Debug.Assert(clipWinMsgSinkMock != null);
            Debug.Assert(clipWinMsgSinkMock.Mock != null);
            /* GIVEN */
            hookNativeMethods.AllowMessageTypeRegistry(GlobalHook.MessageType.WM_CLIPBOARDUPDATE);
            hookNativeMethods.AllowMessageTypeRegistry(GlobalHook.MessageType.WM_PASTE);
            hookNativeMethods.AllowMessageTypeRegistry(GlobalHook.MessageType.WM_CUT);

            hookNativeMethods.AllowLibraryLoad();

            clipWinMsgSinkMock.Dispose();
            nativeClipboard.GetText();

            clipboardModule.Initialize(true);
            clipboardCopyEventProducer.StartCapture(clipWinMsgSinkMock.Mock.Object, nativeClipboard.Mock.Object);


            using var consumedEvent = new CountdownEvent(1);

            using var didStartConsumingEvent = new ManualResetEvent(false);

            var thread = new Thread(async() =>
            {
                await foreach (var @event in Await(
                                   clipboardCopyEventProducer.GetEvents(), didStartConsumingEvent))
                {
                    if ([email protected]("ClipboardText"))
                    {
                        continue;
                    }

                    consumedEvent.Signal();
                }
            });

            thread.Start();

            Assert.IsTrue(didStartConsumingEvent.WaitOne(MaxWaitTime));
            clipWinMsgSinkMock.ClipboardUpdateCopy();

            /* THEN */
            Assert.IsTrue(consumedEvent.Wait(MaxWaitTime), "Did not find all matching clipboard copy event in time.");
            clipboardCopyEventProducer.StopCapture();
            clipboardModule.Initialize(false);
        }
示例#2
0
        public void ClipboardPasteEventProducerCallbackTest()
        {
            /* PRECONDITIONS */
            Debug.Assert(clipboardModule != null);
            Debug.Assert(clipboardPasteEventProducer != null);
            Debug.Assert(hookNativeMethods != null);
            Debug.Assert(hookNativeMethods.Mock != null);
            Debug.Assert(nativeClipboard != null);
            Debug.Assert(nativeClipboard.Mock != null);

            /* GIVEN */
            var callback = GetCallback();

            nativeClipboard.GetText();

            using var consumedEvent = new CountdownEvent(1);

            using var didStartConsumingEvent = new ManualResetEvent(false);

            var thread = new Thread(async() =>
            {
                await foreach (var @event in Await(
                                   clipboardPasteEventProducer.GetEvents(), didStartConsumingEvent))
                {
                    if ([email protected]("ClipboardText"))
                    {
                        continue;
                    }

                    consumedEvent.Signal();
                }
            });

            thread.Start();

            Assert.IsTrue(didStartConsumingEvent.WaitOne(MaxWaitTime));
            callback(new GlobalHook.HookMessage
            {
                Type = (uint)GlobalHook.MessageType.WM_PASTE
            });

            /* THEN */
            Assert.IsTrue(consumedEvent.Wait(MaxWaitTime), "Did not find all matching clipboard paste event in time.");

            //total shut down and resources release
            clipboardPasteEventProducer.StopCapture();
            clipboardModule.Initialize(false);
        }
示例#3
0
        public void TestClipboardModule_Activate()
        {
            /* PRECONDITIONS */
            Debug.Assert(clipboardModule != null);
            Debug.Assert(clipboardCopyEventProducer != null);
            Debug.Assert(clipboardCutEventProducer != null);
            Debug.Assert(clipboardPasteEventProducer != null);
            Debug.Assert(hookNativeMethods != null);

            /* GIVEN */

            /* WHEN */
            clipboardModule.Initialize(true);
            hookNativeMethods.AllowMessageTypeRegistry(GlobalHook.MessageType.WM_CLIPBOARDUPDATE);
            hookNativeMethods.AllowMessageTypeRegistry(GlobalHook.MessageType.WM_PASTE);
            hookNativeMethods.AllowMessageTypeRegistry(GlobalHook.MessageType.WM_CUT);
            hookNativeMethods.AllowLibraryLoad();
            clipboardModule.IsActive = true;

            /* THEN */
            Assert.IsTrue(clipboardModule.IsActive);
            clipboardModule.IsActive = false;
        }