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)); }
public void SetUp() { _listener = Substitute.For <SbListener>(); _listenerSubscriber = Substitute.For <LldbListenerSubscriber>(_listener); _eventManager = new LldbEventManager .Factory(new BoundBreakpointEnumFactory(), null) .Create(null, null, null, null, _listenerSubscriber); }
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)); }
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)); }
public void SetUp() { _mockSbListener = Substitute.For <SbListener>(); _mockSbProcess = Substitute.For <SbProcess>(); _mockSbEvent = Substitute.For <SbEvent>(); _mockRemoteThread = Substitute.For <RemoteThread>(); _mockBreakpointManager = Substitute.For <IBreakpointManager>(); _mockDebugEngineHandler = Substitute.For <IDebugEngineHandler>(); _mockPendingBreakpoint1 = Substitute.For <IPendingBreakpoint>(); _mockPendingBreakpoint2 = Substitute.For <IPendingBreakpoint>(); _mockBoundBreakpoint1 = Substitute.For <IBoundBreakpoint>(); _mockBoundBreakpoint2 = Substitute.For <IBoundBreakpoint>(); _mockBoundBreakpoint3 = Substitute.For <IBoundBreakpoint>(); _mockWatchpoint = Substitute.For <IWatchpoint>(); _mockProgram = Substitute.For <IGgpDebugProgram>(); MockEvent(EventType.STATE_CHANGED, StateType.STOPPED, false); MockListener(_mockSbEvent, true); MockThread(_mockRemoteThread, StopReason.BREAKPOINT, _breakpointStopData); MockProcess(new List <RemoteThread> { _mockRemoteThread }); MockBreakpointManager(); _mockListenerSubscriber = Substitute.For <LldbListenerSubscriber>(_mockSbListener); var threadContext = new FakeMainThreadContext(); _eventManager = new LldbEventManager .Factory(new BoundBreakpointEnumFactory(), threadContext.JoinableTaskContext) .Create(_mockDebugEngineHandler, _mockBreakpointManager, _mockProgram, _mockSbProcess, _mockListenerSubscriber); var lldbEventManager = _eventManager as LldbEventManager; lldbEventManager?.SubscribeToChanges(); }