OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #ifndef DEBUGGER_CORE_DEBUG_API_MOCK_H_ | |
5 #define DEBUGGER_CORE_DEBUG_API_MOCK_H_ | |
6 #include <deque> | |
7 #include "debugger/core/debug_api.h" | |
8 | |
9 namespace debug { | |
10 /// This class is a mock of DebugAPI, used in unit tests. | |
11 /// | |
12 /// This is pure mock, Windows API is never called. | |
13 /// |DebugAPIMock| keeps a queue of function call, | |
14 /// so that sequence of API calls can be verified by |CompareCallSequence|. | |
15 /// Parameters of the API calls are not tracked / verified. | |
16 class DebugAPIMock : public DebugAPI { | |
17 public: | |
18 enum FunctionId { | |
19 kCreateProcess, | |
20 kCloseHandle, | |
21 kReadProcessMemory, | |
22 kWriteProcessMemory, | |
23 kFlushInstructionCache, | |
24 kGetThreadContext, | |
25 kSetThreadContext, | |
26 kWaitForDebugEvent, | |
27 kContinueDebugEvent, | |
28 kTerminateThread, | |
29 kDebugBreakProcess, | |
30 kWow64GetThreadContext, | |
31 kWow64SetThreadContext, | |
32 kIsWoW64Process, | |
33 kDebugActiveProcess, | |
34 kDebugActiveProcessStop, | |
35 }; | |
36 | |
37 DebugAPIMock(); | |
38 | |
39 void ClearCallSequence(); | |
40 bool CompareCallSequence(const std::deque<FunctionId>& call_list) const; | |
41 | |
42 virtual BOOL CreateProcess(LPCTSTR lpApplicationName, | |
43 LPTSTR lpCommandLine, | |
44 LPSECURITY_ATTRIBUTES lpProcessAttributes, | |
45 LPSECURITY_ATTRIBUTES lpThreadAttributes, | |
46 BOOL bInheritHandles, | |
47 DWORD dwCreationFlags, | |
48 LPVOID lpEnvironment, | |
49 LPCTSTR lpCurrentDirectory, | |
50 LPSTARTUPINFO lpStartupInfo, | |
51 LPPROCESS_INFORMATION lpProcessInformation); | |
52 | |
53 virtual BOOL CloseHandle(HANDLE hObject); | |
54 | |
55 virtual BOOL ReadProcessMemory(HANDLE hProcess, | |
56 LPCVOID lpBaseAddress, | |
57 LPVOID lpBuffer, | |
58 SIZE_T nSize, | |
59 SIZE_T *lpNumberOfBytesRead); | |
60 | |
61 virtual BOOL WriteProcessMemory(HANDLE hProcess, | |
62 LPVOID lpBaseAddress, | |
63 LPCVOID lpBuffer, | |
64 SIZE_T nSize, | |
65 SIZE_T *lpNumberOfBytesWritten); | |
66 | |
67 virtual BOOL FlushInstructionCache(HANDLE hProcess, | |
68 LPCVOID lpBaseAddress, | |
69 SIZE_T dwSize); | |
70 | |
71 | |
72 virtual BOOL GetThreadContext(HANDLE hThread, LPCONTEXT lpContext); | |
73 virtual BOOL SetThreadContext(HANDLE hThread, CONTEXT *lpContext); | |
74 | |
75 virtual BOOL WaitForDebugEvent(LPDEBUG_EVENT lpDebugEvent, | |
76 DWORD dwMilliseconds); | |
77 | |
78 virtual BOOL ContinueDebugEvent(DWORD dwProcessId, | |
79 DWORD dwThreadId, | |
80 DWORD dwContinueStatus); | |
81 | |
82 virtual BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode); | |
83 virtual BOOL DebugBreakProcess(HANDLE Process); | |
84 | |
85 virtual BOOL Wow64GetThreadContext(HANDLE hThread, PWOW64_CONTEXT lpContext); | |
86 virtual BOOL Wow64SetThreadContext(HANDLE hThread, | |
87 const WOW64_CONTEXT* lpContext); | |
88 virtual BOOL IsWoW64Process(HANDLE hProcess, PBOOL Wow64Process); | |
89 virtual BOOL DebugActiveProcess(DWORD dwProcessId); | |
90 virtual BOOL DebugActiveProcessStop(DWORD dwProcessId); | |
91 | |
92 bool single_step_enabled_; | |
93 std::deque<FunctionId> called_functions_; | |
94 }; | |
95 } // namespace debug | |
96 | |
97 #endif // DEBUGGER_CORE_DEBUG_API_MOCK_H_ | |
98 | |
OLD | NEW |