public void SetNextStatementCannot() { var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = Substitute.For <IDebugThread2>(); return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); Assert.AreEqual(VSConstants.E_FAIL, thread.SetNextStatement(mockStackFrame, mockCodeContext)); }
public void SetNextStatementFailToJump() { // We need CanSetNextStatement() to pass in order to execute SetNexStatement(). const string NAME = "test"; const ulong ADDRESS = 0xabcd; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); var contextInfoFields = enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION; System.Action <CONTEXT_INFO[]> setContext = (infos => { infos[0].bstrFunction = NAME; infos[0].bstrAddress = "0xabcd"; infos[0].dwFields = contextInfoFields; }); mockCodeContext .GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContext)) .Returns(VSConstants.S_OK); ((IDebugMemoryContext2)mockCodeContext) .GetInfo(Arg.Any <enum_CONTEXT_INFO_FIELDS>(), Arg.Do(setContext)) .Returns(VSConstants.S_OK); const string DIR = "path\\to"; const string FILE_NAME = "file"; const uint LINE = 2; var mockProcess = Substitute.For <SbProcess>(); mockThread.GetProcess().Returns(mockProcess); var mockTarget = Substitute.For <RemoteTarget>(); mockProcess.GetTarget().Returns(mockTarget); var mockAddress = Substitute.For <SbAddress>(); var lineEntry = Substitute.For <LineEntryInfo>(); lineEntry.Directory = DIR; lineEntry.FileName = FILE_NAME; lineEntry.Line = LINE; var mockError = Substitute.For <SbError>(); mockError.Fail().Returns(true); mockError.GetCString().Returns("JumpToLine() failed for some reason."); mockThread.JumpToLine(Path.Combine(DIR, FILE_NAME), LINE).Returns(mockError); mockAddress.GetLineEntry().Returns(lineEntry); mockTarget.ResolveLoadAddress(ADDRESS).Returns(mockAddress); Assert.AreEqual(VSConstants.E_FAIL, thread.SetNextStatement(mockStackFrame, mockCodeContext)); }
public void SetNextStatement() { // We need CanSetNextStatement() to pass in order to execute SetNexStatement(). const string NAME = "test"; const ulong ADDRESS = 0xabcd; var threadId = 1u; var mockThread = Substitute.For <RemoteThread>(); mockThread.GetThreadId().Returns(threadId); var mockStackFrame = Substitute.For <IDebugStackFrame2>(); string name; mockStackFrame.GetName(out name).Returns(x => { x[0] = NAME; return(VSConstants.S_OK); }); IDebugThread2 outThread; IDebugThread thread = CreateDebugThread <IDebugThread>(mockThread); mockStackFrame.GetThread(out outThread).Returns(x => { x[0] = thread; return(VSConstants.S_OK); }); var mockCodeContext = Substitute.For <IDebugCodeContext2>(); var contextInfosDestination = Arg.Any <CONTEXT_INFO[]>(); mockCodeContext.GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS | enum_CONTEXT_INFO_FIELDS.CIF_FUNCTION, contextInfosDestination).Returns(x => { var infos = x[1] as CONTEXT_INFO[]; infos[0] = new CONTEXT_INFO { bstrFunction = NAME, bstrAddress = "0x" + ADDRESS.ToString("x16"), }; return(VSConstants.S_OK); }); IDebugDocumentContext2 documentContext; var mockDocumentContext = Substitute.For <IDebugDocumentContext2>(); mockCodeContext.GetDocumentContext(out documentContext).Returns(x => { x[0] = mockDocumentContext; return(VSConstants.S_OK); }); const uint LINE = 2; const string PATH = "path\\to\\file"; string path; mockDocumentContext.GetName(enum_GETNAME_TYPE.GN_FILENAME, out path).Returns(x => { x[1] = PATH; return(VSConstants.S_OK); }); mockDocumentContext.GetStatementRange( Arg.Any <TEXT_POSITION[]>(), Arg.Any <TEXT_POSITION[]>()).Returns(x => { var startPosition = x[0] as TEXT_POSITION[]; startPosition[0].dwLine = LINE; return(VSConstants.S_OK); }); var mockError = Substitute.For <SbError>(); mockError.Fail().Returns(false); mockThread.JumpToLine(PATH, LINE).Returns(mockError); Assert.AreEqual(VSConstants.S_OK, thread.SetNextStatement(mockStackFrame, mockCodeContext)); mockThread.Received(1).JumpToLine(PATH, LINE + 1); }