Covellite++  Version: 2.3.0 Revision: ??? Platform: x64 Build: 23:13 04.01.2025
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
Windows.mock.hpp
1
2#pragma once
3
4#if BOOST_OS_WINDOWS
5
6// Без Windows.h не компилируется
7#include <alicorn/platform/windows.hpp>
8//#include <windef.h>
9//#include <winuser.h>
10
11#define NOGDICAPMASKS
12//#define NOVIRTUALKEYCODES
13//#define NOWINMESSAGES
14//#define NOWINSTYLES
15//#define NOSYSMETRICS
16#define NOMENUS
17#define NOICONS
18#define NOKEYSTATES
19#define NOSYSCOMMANDS
20#define NORASTEROPS
21//#define NOSHOWWINDOW
22#define OEMRESOURCE
23#define NOATOM
24#define NOCLIPBOARD
25#define NOCOLOR
26#define NOCTLMGR
27#define NODRAWTEXT
28//#define NOGDI
29#define NOKERNEL
30//#define NOUSER
31#define NONLS
32//#define NOMB
33#define NOMEMMGR
34#define NOMETAFILE
35#define NOMINMAX
36//#define NOMSG
37#define NOOPENFILE
38#define NOSCROLL
39#define NOSERVICE
40#define NOSOUND
41#define NOTEXTMETRIC
42#define NOWH
43//#define NOWINOFFSETS
44#define NOCOMM
45#define NOKANJI
46#define NOHELP
47#define NOPROFILER
48#define NODEFERWINDOWPOS
49#define NOMCX
50
51#include <Windows.h>
52#undef GetCommandLine
53
54inline bool operator== (const MSG & _Left, const MSG & _Right)
55{
56 if (_Left.message != _Right.message) return false;
57 if (_Left.hwnd != _Right.hwnd) return false;
58 if (_Left.wParam != _Right.wParam) return false;
59 if (_Left.lParam != _Right.lParam) return false;
60 if (_Left.time != _Right.time) return false;
61 if (_Left.pt.x != _Right.pt.x) return false;
62 if (_Left.pt.y != _Right.pt.y) return false;
63 return true;
64}
65
66namespace mock
67{
68
69class WindowsProxy :
70 public ::alicorn::extension::testing::Proxy<WindowsProxy>
71{
72public:
73 MOCK_METHOD4(MessageBoxA, int (HWND, ::std::string, ::std::string, UINT));
74 MOCK_METHOD1(PostQuitMessage, void(int));
75 MOCK_METHOD1(RegisterClassExW, ATOM(WNDCLASSEXW *));
76 MOCK_METHOD1(GetModuleHandleW, HMODULE(LPCWSTR));
77 MOCK_METHOD2(UnregisterClassW, BOOL(::std::wstring, HINSTANCE));
78 MOCK_METHOD2(GetWindowLongPtrW, LONG_PTR (HWND, int));
79 MOCK_METHOD2(SetWindowLongPtrW, LONG_PTR (HWND, int));
80 MOCK_METHOD4(DefWindowProcW, LRESULT(HWND, UINT, WPARAM, LPARAM));
81 MOCK_METHOD4(PeekMessageW, BOOL(HWND, UINT, UINT, UINT));
82 MOCK_METHOD3(GetMessageW, BOOL(HWND, UINT, UINT));
83 MOCK_METHOD0(BuildMessage, MSG(void));
84 MOCK_METHOD1(TranslateMessage, BOOL(MSG));
85 MOCK_METHOD1(DispatchMessageW, LRESULT(MSG));
86 MOCK_METHOD1(Sleep, void(DWORD));
87 MOCK_METHOD10(CreateWindowExW1, void(DWORD, ::std::wstring, ::std::wstring,
88 DWORD, int, int, int, int, HWND, HMENU));
89 MOCK_METHOD2(CreateWindowExW2, HWND(HINSTANCE, LPVOID));
90 MOCK_METHOD1(DestroyWindow, BOOL(HWND));
91 MOCK_METHOD2(ShowWindow, BOOL(HWND, int));
92 MOCK_METHOD1(GetUserDefaultLocaleName, int(int));
93 MOCK_METHOD0(GetLocaleName, ::std::wstring(void));
94 MOCK_METHOD2(LoadCursorW, HCURSOR (HINSTANCE, ULONG_PTR));
95 MOCK_METHOD2(LoadIconW, HICON(HINSTANCE, ::std::wstring));
96 MOCK_METHOD1(GetDC, HDC (HWND));
97 MOCK_METHOD2(ReleaseDC, int (HWND, HDC));
98 MOCK_METHOD2(ChoosePixelFormat, int (HDC, const PIXELFORMATDESCRIPTOR *));
99 MOCK_METHOD3(SetPixelFormat, BOOL (HDC, int, const PIXELFORMATDESCRIPTOR *));
100 MOCK_METHOD1(wglCreateContext, HGLRC (HDC));
101 MOCK_METHOD2(wglMakeCurrent, BOOL (HDC, HGLRC));
102 MOCK_METHOD1(wglDeleteContext, BOOL (HGLRC _hRc));
103 MOCK_METHOD0(BuildRect, RECT(void));
104 MOCK_METHOD1(GetClientRect, BOOL (HWND));
105 MOCK_METHOD1(SwapBuffers, BOOL (HDC));
106 MOCK_METHOD0(GetCommandLineA, LPSTR (VOID));
107 MOCK_METHOD4(SetClientRect, void(LONG, LONG, LONG, LONG));
108 MOCK_METHOD3(AdjustWindowRectEx, BOOL (DWORD, BOOL, DWORD));
109 MOCK_METHOD1(GetSystemMetrics, int (int));
110
111public:
112 LONG_PTR m_NewLongPtr = NULL;
113};
114
115inline int MessageBoxA(HWND _hWnd, LPCSTR _Text, LPCSTR _Caption, UINT _Type)
116{
117 return WindowsProxy::GetInstance()->MessageBoxA(_hWnd, _Text, _Caption, _Type);
118}
119
120inline void PostQuitMessage(int _ExitCode)
121{
122 WindowsProxy::GetInstance()->PostQuitMessage(_ExitCode);
123}
124
125inline HMODULE GetModuleHandleW(LPCWSTR _ModuleName)
126{
127 return WindowsProxy::GetInstance()->GetModuleHandleW(_ModuleName);
128}
129
130inline ATOM RegisterClassExW(WNDCLASSEXW * _pWindowClass)
131{
132 return WindowsProxy::GetInstance()->RegisterClassExW(_pWindowClass);
133}
134
135inline BOOL UnregisterClassW(LPCWSTR _ClassName, HINSTANCE _hInstance)
136{
137 return WindowsProxy::GetInstance()->UnregisterClassW(_ClassName, _hInstance);
138}
139
140inline LONG_PTR GetWindowLongPtrW(HWND _hWnd, int _Index)
141{
142 return WindowsProxy::GetInstance()->GetWindowLongPtrW(_hWnd, _Index);
143}
144
145inline LONG_PTR SetWindowLongPtrW(HWND _hWnd, int _Index, LONG_PTR _NewLong)
146{
147 WindowsProxy::GetInstance()->m_NewLongPtr = _NewLong;
148 return WindowsProxy::GetInstance()->SetWindowLongPtrW(_hWnd, _Index);
149}
150
151inline LRESULT DefWindowProcW(HWND _hWnd, UINT _Msg, WPARAM _wParam, LPARAM _lParam)
152{
153 return WindowsProxy::GetInstance()->DefWindowProcW(_hWnd, _Msg, _wParam, _lParam);
154}
155
156inline BOOL PeekMessageW(MSG * _pMsg, HWND _hWnd, UINT _MsgFilterMin,
157 UINT _MsgFilterMax, UINT _RemoveMsg)
158{
159 const auto Result = WindowsProxy::GetInstance()->PeekMessageW(_hWnd,
160 _MsgFilterMin, _MsgFilterMax, _RemoveMsg);
161
162 if (Result != FALSE)
163 {
164 (*_pMsg) = WindowsProxy::GetInstance()->BuildMessage();
165 }
166
167 return Result;
168}
169
170inline BOOL GetMessageW(MSG * _pMsg, HWND _hWnd,
171 UINT _MsgFilterMin, UINT _MsgFilterMax)
172{
173 const auto Result = WindowsProxy::GetInstance()->GetMessageW(_hWnd,
174 _MsgFilterMin, _MsgFilterMax);
175
176 if (Result != -1)
177 {
178 (*_pMsg) = WindowsProxy::GetInstance()->BuildMessage();
179 }
180
181 return Result;
182}
183
184inline VOID Sleep(DWORD _Milliseconds)
185{
186 WindowsProxy::GetInstance()->Sleep(_Milliseconds);
187}
188
189inline BOOL TranslateMessage(const MSG * _pMsg)
190{
191 return WindowsProxy::GetInstance()->TranslateMessage(*_pMsg);
192}
193
194inline LRESULT DispatchMessageW(const MSG * _pMsg)
195{
196 return WindowsProxy::GetInstance()->DispatchMessageW(*_pMsg);
197}
198
199inline HWND CreateWindowExW(DWORD _ExStyle, LPCWSTR _ClassName,
200 LPCWSTR _WindowName, DWORD _Style, int _X, int _Y, int _Width, int _Height,
201 HWND _hWndParent, HMENU _hMenu, HINSTANCE _hInstance, LPVOID _pParam)
202{
203 WindowsProxy::GetInstance()->CreateWindowExW1(_ExStyle, _ClassName,
204 _WindowName, _Style, _X, _Y, _Width, _Height, _hWndParent, _hMenu);
205 return WindowsProxy::GetInstance()->CreateWindowExW2(_hInstance, _pParam);
206}
207
208inline BOOL DestroyWindow(HWND _hWnd)
209{
210 return WindowsProxy::GetInstance()->DestroyWindow(_hWnd);
211}
212
213inline BOOL ShowWindow(HWND _hWnd, int _CmdShow)
214{
215 return WindowsProxy::GetInstance()->ShowWindow(_hWnd, _CmdShow);
216}
217
218inline int GetUserDefaultLocaleName(LPWSTR _LocaleName, int _LocaleNameCount)
219{
220 const auto LocaleName = WindowsProxy::GetInstance()->GetLocaleName();
221 memcpy_s(_LocaleName, _LocaleNameCount * sizeof(wchar_t),
222 LocaleName.data(), LocaleName.size() * sizeof(wchar_t));
223
224 return WindowsProxy::GetInstance()->GetUserDefaultLocaleName(_LocaleNameCount);
225}
226
227inline HCURSOR LoadCursorW(HINSTANCE _hInstance, LPCWSTR _pCursorName)
228{
229 return WindowsProxy::GetInstance()->LoadCursorW(_hInstance, (ULONG_PTR)_pCursorName);
230}
231
232inline HICON LoadIconW(HINSTANCE _hInstance, LPCWSTR _pIconName)
233{
234 return WindowsProxy::GetInstance()->LoadIconW(_hInstance, _pIconName);
235}
236
237inline HDC GetDC(HWND _hWnd)
238{
239 return WindowsProxy::GetInstance()->GetDC(_hWnd);
240}
241
242inline int ReleaseDC(HWND _hWnd, HDC _hDC)
243{
244 return WindowsProxy::GetInstance()->ReleaseDC(_hWnd, _hDC);
245}
246
247inline int ChoosePixelFormat(HDC _hDc, const PIXELFORMATDESCRIPTOR * _pPfd)
248{
249 return WindowsProxy::GetInstance()->ChoosePixelFormat(_hDc, _pPfd);
250}
251
252inline BOOL SetPixelFormat(HDC _hDc, int _PixelFormat,
253 const PIXELFORMATDESCRIPTOR * _pPfd)
254{
255 return WindowsProxy::GetInstance()->SetPixelFormat(_hDc, _PixelFormat, _pPfd);
256}
257
258inline HGLRC wglCreateContext(HDC _hDc)
259{
260 return WindowsProxy::GetInstance()->wglCreateContext(_hDc);
261}
262
263inline BOOL wglMakeCurrent(HDC _hDc, HGLRC _hRc)
264{
265 return WindowsProxy::GetInstance()->wglMakeCurrent(_hDc, _hRc);
266}
267
268inline BOOL wglDeleteContext(HGLRC _hRc)
269{
270 return WindowsProxy::GetInstance()->wglDeleteContext(_hRc);
271}
272
273inline BOOL GetClientRect(HWND _hWnd, LPRECT _pRect)
274{
275 *_pRect = WindowsProxy::GetInstance()->BuildRect();
276 return WindowsProxy::GetInstance()->GetClientRect(_hWnd);
277}
278
279inline BOOL SwapBuffers(HDC _hDc)
280{
281 return WindowsProxy::GetInstance()->SwapBuffers(_hDc);
282}
283
284inline LPSTR GetCommandLineA(VOID)
285{
286 return WindowsProxy::GetInstance()->GetCommandLineA();
287}
288
289inline BOOL AdjustWindowRectEx(RECT * _pRect, DWORD _Style, BOOL _IsMenu,
290 DWORD _ExStyle)
291{
292 WindowsProxy::GetInstance()->SetClientRect(
293 _pRect->left, _pRect->top, _pRect->right, _pRect->bottom);
294 *_pRect = WindowsProxy::GetInstance()->BuildRect();
295 return WindowsProxy::GetInstance()->AdjustWindowRectEx(_Style, _IsMenu, _ExStyle);
296}
297
298inline int GetSystemMetrics(int _Index)
299{
300 return WindowsProxy::GetInstance()->GetSystemMetrics(_Index);
301}
302
303} // namespace mock
304
305namespace covellite
306{
307
308namespace app
309{
310
311using ::mock::MessageBoxA;
312using ::mock::GetModuleHandleW;
313using ::mock::RegisterClassExW;
314using ::mock::UnregisterClassW;
315using ::mock::GetWindowLongPtrW;
316using ::mock::DefWindowProcW;
317using ::mock::PeekMessageW;
318using ::mock::GetMessageW;
319using ::mock::Sleep;
320using ::mock::TranslateMessage;
321using ::mock::DispatchMessage;
322using ::mock::LoadCursorW;
323using ::mock::LoadIconW;
324using ::mock::GetCommandLineA;
325using ::mock::PostQuitMessage;
326
327} // namespace app
328
329namespace os
330{
331
332using ::mock::GetModuleHandleW;
333using ::mock::CreateWindowEx;
334using ::mock::ShowWindow;
335using ::mock::DestroyWindow;
336using ::mock::GetUserDefaultLocaleName;
337using ::mock::AdjustWindowRectEx;
338using ::mock::GetSystemMetrics;
339using ::mock::PostQuitMessage;
340using ::mock::SetWindowLongPtrW;
341using ::mock::GetClientRect;
342
343} // namespace os
344
345namespace api
346{
347
348using ::mock::GetDC;
349using ::mock::ReleaseDC;
350using ::mock::ChoosePixelFormat;
351using ::mock::SetPixelFormat;
352using ::mock::wglCreateContext;
353using ::mock::wglMakeCurrent;
354using ::mock::wglDeleteContext;
355using ::mock::GetClientRect;
356using ::mock::SwapBuffers;
357
358} // namespace api
359
360} // namespace covellite
361
362#endif