public void GetCodeContext() { var mockCodeContext = Substitute.For <IDebugCodeContext2>(); mockCodeContextFactory .Create(TEST_PC, NAME, mockDocumentContext, Guid.Empty) .Returns(mockCodeContext); Assert.AreEqual(VSConstants.S_OK, stackFrame.GetCodeContext(out IDebugCodeContext2 codeContext)); Assert.AreEqual(codeContext, mockCodeContext); }
public void GetCodeContext() { const ulong newAddress = 0x123456789a; SbAddress address = Substitute.For <SbAddress>(); var documentContext = Substitute.For <IDebugDocumentContext2>(); var newCodeContext = Substitute.For <IDebugCodeContext2>(); _mockTarget.ResolveLoadAddress(newAddress).Returns(address); _documentContextFactory.Create(address.GetLineEntry()).Returns(documentContext); _codeContextFactory .Create(newAddress, Arg.Any <Lazy <string> >(), documentContext, Guid.Empty) .Returns(newCodeContext); Assert.AreEqual(VSConstants.S_OK, _disassemblyStream.GetCodeContext( newAddress, out IDebugCodeContext2 codeContext)); Assert.AreEqual(newCodeContext, codeContext); }
public void EnumCodeContexts(int numLocations) { var mockDocumentPosition = Substitute.For <IDebugDocumentPosition2>(); mockDocumentPosition.GetRange(Arg.Any <TEXT_POSITION[]>(), null).Returns(x => { var startPositions = x[0] as TEXT_POSITION[]; startPositions[0].dwLine = LINE; return(VSConstants.S_OK); }); mockDocumentPosition.GetFileName(out string _).Returns(x => { x[0] = Path.Combine(DIRECTORY, FILE_NAME); return(VSConstants.S_OK); }); var mockBreakpoint = Substitute.For <RemoteBreakpoint>(); var mockCodeContexts = new IDebugCodeContext2[numLocations]; for (uint i = 0; i < numLocations; ++i) { var mockAddress = Substitute.For <SbAddress>(); mockAddress.GetLoadAddress(mockRemoteTarget).Returns(ADDRESS + i); var mockFunction = Substitute.For <SbFunction>(); mockFunction.GetName().Returns(NAME + i); mockAddress.GetFunction().Returns(mockFunction); var lineEntry = new LineEntryInfo(); mockAddress.GetLineEntry().Returns(lineEntry); var mockDocumentContext = Substitute.For <IDebugDocumentContext2>(); mockDocumentContextFactory.Create(lineEntry).Returns(mockDocumentContext); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); mockCodeContextFactory .Create(ADDRESS + i, NAME + i, mockDocumentContext, Guid.Empty) .Returns(mockCodeContext); var mockBreakpointLocation = Substitute.For <SbBreakpointLocation>(); mockBreakpointLocation.GetAddress().Returns(mockAddress); mockBreakpoint.GetLocationAtIndex(i).Returns(mockBreakpointLocation); mockCodeContexts[i] = mockCodeContext; } mockBreakpoint.GetNumLocations().Returns((uint)numLocations); mockRemoteTarget.BreakpointCreateByLocation(Path.Combine(DIRECTORY, FILE_NAME), LINE + 1).Returns(mockBreakpoint); int result = program.EnumCodeContexts(mockDocumentPosition, out IEnumDebugCodeContexts2 enumCodeContexts); Assert.AreEqual(VSConstants.S_OK, result); enumCodeContexts.GetCount(out uint count); Assert.AreEqual(numLocations, count); IDebugCodeContext2[] codeContexts = new IDebugCodeContext2[count]; uint actual = 0; enumCodeContexts.Next(count, codeContexts, ref actual); Assert.AreEqual(count, actual); Assert.AreEqual(mockCodeContexts, codeContexts); }
public void GetBreakpointResolutionNullLineEntry() { mockAddress.GetLineEntry().Returns((LineEntryInfo)null); mockBreakpointLocation.GetAddress().Returns(mockAddress); mockBreakpointResolutionFactory.Create(mockCodeContext, mockprogram).Returns( mockBreakpointResolution); mockCodeContextFactory.Create(ADDRESS, "", null, Guid.Empty).Returns(mockCodeContext); var boundBreakpointNullLineEntry = boundBreakpointFactory.Create( mockPendingBreakpoint, mockBreakpointLocation, mockprogram, Guid.Empty); IDebugBreakpointResolution2 output; Assert.AreEqual(VSConstants.S_OK, boundBreakpointNullLineEntry.GetBreakpointResolution(out output)); Assert.AreEqual(mockBreakpointResolution, output); }
public void GetMemoryContext() { const string VAR_NAME = "test"; const ulong EXPECTED_ADDRESS = 0xdeadbeef; mockVarInfo.DisplayName.Returns(VAR_NAME); mockVarInfo.GetMemoryContextAddress().Returns <ulong?>(EXPECTED_ADDRESS); IDebugCodeContext2 mockCodeContext = Substitute.For <IDebugCodeContext2>(); mockCodeContextFactory.Create(EXPECTED_ADDRESS, VAR_NAME, null, Guid.Empty) .Returns(mockCodeContext); var debugProperty = createPropertyDelegate.Invoke(mockVarInfo); IDebugMemoryContext2 memoryContext; Assert.AreEqual(VSConstants.S_OK, debugProperty.GetMemoryContext(out memoryContext)); Assert.AreEqual(mockCodeContext, memoryContext); }
public void SetUp() { string name = ""; mockBreakpoint = Substitute.For <RemoteBreakpoint>(); lineEntry = new LineEntryInfo(); mockPendingBreakpoint = Substitute.For <IDebugPendingBreakpoint2>(); mockBreakpointLocation = Substitute.For <SbBreakpointLocation>(); mockAddress = Substitute.For <SbAddress>(); mockAddress.GetLineEntry().Returns(lineEntry); mockBreakpointLocation.GetHitCount().Returns(HIT_COUNT); mockBreakpointLocation.GetLoadAddress().Returns(ADDRESS); mockBreakpointLocation.GetBreakpoint().Returns(mockBreakpoint); mockBreakpointLocation.GetId().Returns(ID); mockBreakpointLocation.GetAddress().Returns(mockAddress); mockprogram = Substitute.For <IDebugProgram2>(); mockDocumentContext = Substitute.For <IDebugDocumentContext2>(); mockDocumentContext.GetName(enum_GETNAME_TYPE.GN_NAME, out name).Returns( x => { x[1] = NAME; return(VSConstants.S_OK); }); mockBreakpointResolution = Substitute.For <IDebugBreakpointResolution2>(); mockDocumentContextFactory = Substitute.For <DebugDocumentContext.Factory>(); mockDocumentContextFactory.Create(lineEntry).Returns(mockDocumentContext); mockCodeContext = Substitute.For <IDebugCodeContext2>(); mockCodeContextFactory = Substitute.For <DebugCodeContext.Factory>(); mockCodeContextFactory.Create(ADDRESS, NAME, mockDocumentContext, Guid.Empty).Returns(mockCodeContext); mockBreakpointResolutionFactory = Substitute.For <DebugBreakpointResolution.Factory>(); mockBreakpointResolutionFactory.Create(mockCodeContext, mockprogram).Returns( mockBreakpointResolution); boundBreakpointFactory = new DebugBoundBreakpoint.Factory(mockDocumentContextFactory, mockCodeContextFactory, mockBreakpointResolutionFactory); boundBreakpoint = boundBreakpointFactory.Create( mockPendingBreakpoint, mockBreakpointLocation, mockprogram, Guid.Empty); }