示例#1
0
        public void SubscriberWithEventRaisingExceptionTest()
        {
            var eventReceived  = new AutoResetEvent(false);
            var mockSbListener = Substitute.For <SbListener>();

            mockSbListener.WaitForEvent(Arg.Any <uint>(), out var _).Throws(new Exception("oops"));

            var lldbListenerSubscriber = new LldbListenerSubscriber(mockSbListener);

            var calledStateChanged      = 0;
            var calledExceptionOccured  = 0;
            var calledFileUpdate        = 0;
            var calledBreakpointChanged = 0;

            lldbListenerSubscriber.StateChanged += (c, e) =>
                                                   UpdateCounterAndSetEventReceived(ref calledStateChanged, eventReceived);
            lldbListenerSubscriber.ExceptionOccured += (c, e) =>
                                                       UpdateCounterAndSetEventReceived(ref calledExceptionOccured, eventReceived);
            lldbListenerSubscriber.FileUpdateReceived += (c, e) =>
                                                         UpdateCounterAndSetEventReceived(ref calledFileUpdate, eventReceived);
            lldbListenerSubscriber.BreakpointChanged += (c, e) =>
                                                        UpdateCounterAndSetEventReceived(ref calledBreakpointChanged, eventReceived);

            lldbListenerSubscriber.Start();
            Assert.IsTrue(eventReceived.WaitOne(_maxTimeSpanWaitingForEvent));
            lldbListenerSubscriber.Stop();

            Assert.That(calledExceptionOccured, Is.EqualTo(1));
            Assert.That(calledStateChanged, Is.EqualTo(0));
            Assert.That(calledFileUpdate, Is.EqualTo(0));
            Assert.That(calledBreakpointChanged, Is.EqualTo(0));
        }
示例#2
0
        public void SubscriberWithFileUpdateAvailableTest()
        {
            var eventReceived = new AutoResetEvent(false);
            var mockSbEvent   = Substitute.For <SbEvent>();

            mockSbEvent.GetDescription().Returns(_fileUpdateExample);
            mockSbEvent.GetEventType().Returns(EventType.STRUCTURED_DATA);

            var mockSbListener = Substitute.For <SbListener>();

            mockSbListener.WaitForEvent(Arg.Any <uint>(), out var _).Returns(x => {
                x[1] = mockSbEvent;
                return(true);
            });

            var lldbListenerSubscriber = new LldbListenerSubscriber(mockSbListener);

            var calledStateChanged          = 0;
            var calledExceptionOccured      = 0;
            var calledFileUpdate            = 0;
            var calledBreakpointChanged     = 0;
            FileProcessingUpdate fileUpdate = null;

            lldbListenerSubscriber.StateChanged += (c, e) =>
                                                   UpdateCounterAndSetEventReceived(ref calledStateChanged, eventReceived);
            lldbListenerSubscriber.ExceptionOccured += (c, e) =>
                                                       UpdateCounterAndSetEventReceived(ref calledExceptionOccured, eventReceived);
            lldbListenerSubscriber.FileUpdateReceived += (c, e) =>
            {
                calledFileUpdate++;
                fileUpdate = e?.Update;
                eventReceived.Set();
            };
            lldbListenerSubscriber.BreakpointChanged += (c, e) =>
                                                        UpdateCounterAndSetEventReceived(ref calledBreakpointChanged, eventReceived);

            lldbListenerSubscriber.Start();
            Assert.IsTrue(eventReceived.WaitOne(_maxTimeSpanWaitingForEvent));
            lldbListenerSubscriber.Stop();

            Assert.That(calledExceptionOccured, Is.EqualTo(0));
            Assert.That(calledStateChanged, Is.EqualTo(0));
            Assert.That(calledBreakpointChanged, Is.EqualTo(0));
            Assert.That(calledFileUpdate, Is.EqualTo(1));
            Assert.That(fileUpdate, Is.Not.Null);
            Assert.That(fileUpdate.File, Is.EqualTo("/usr/local/cloudcast/lib/libggp.so"));
            Assert.That(fileUpdate.Size, Is.EqualTo(10));
            Assert.That(fileUpdate.Method, Is.EqualTo(FileProcessingState.Read));
        }
示例#3
0
        public void SubscriberWithStateEventInterruptedTest()
        {
            var eventReceived = new AutoResetEvent(false);
            var mockSbEvent   = Substitute.For <SbEvent>();

            mockSbEvent.GetEventType().Returns(EventType.INTERRUPT);

            var mockSbListener = Substitute.For <SbListener>();

            mockSbListener.WaitForEvent(Arg.Any <uint>(), out var _).Returns(x => {
                x[1] = mockSbEvent;
                return(true);
            });

            mockSbListener.WaitForEvent(Arg.Any <uint>(), out var _).Returns(x => {
                eventReceived.Set(); // stop listening for the events
                x[1] = mockSbEvent;
                return(true);
            });

            var lldbListenerSubscriber  = new LldbListenerSubscriber(mockSbListener);
            var calledStateChanged      = 0;
            var calledExceptionOccured  = 0;
            var calledFileUpdate        = 0;
            var calledBreakpointChanged = 0;

            lldbListenerSubscriber.StateChanged += (c, e) =>
                                                   UpdateCounterAndSetEventReceived(ref calledStateChanged, eventReceived);
            lldbListenerSubscriber.ExceptionOccured += (c, e) =>
                                                       UpdateCounterAndSetEventReceived(ref calledExceptionOccured, eventReceived);
            lldbListenerSubscriber.FileUpdateReceived += (c, e) =>
                                                         UpdateCounterAndSetEventReceived(ref calledFileUpdate, eventReceived);
            lldbListenerSubscriber.BreakpointChanged += (c, e) =>
                                                        UpdateCounterAndSetEventReceived(ref calledBreakpointChanged, eventReceived);

            lldbListenerSubscriber.Start();
            Assert.IsTrue(eventReceived.WaitOne(_maxTimeSpanWaitingForEvent));
            lldbListenerSubscriber.Stop();

            Assert.That(calledExceptionOccured, Is.EqualTo(0));
            Assert.That(calledStateChanged, Is.EqualTo(0));
            Assert.That(calledFileUpdate, Is.EqualTo(0));
            Assert.That(calledBreakpointChanged, Is.EqualTo(0));
        }