2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetCursorPos
5 * PROGRAMMERS: Giannis Adamopoulos
14 HHOOK hMouseHookLL
, hMouseHook
;
20 int mouse_move_called
;
23 struct _test_info info
[] = { {0,0,0}, /* SetCursorPos without a window */
24 {1,1,0}, /* mouse_event without a window */
25 {0,1,1}, /* SetCursorPos with a window */
26 {1,1,1}, /* mouse_event with a window */
27 {0,1,1}, /* multiple SetCursorPos with a window with coalescing */
28 {0,2,2}, /* multiple SetCursorPos with a window without coalescing */
29 {2,1,1}, /* multiple mouse_event with a window with coalescing */
30 {2,2,2}, /* multiple mouse_event with a window without coalescing */
33 struct _test_info results
[8];
37 LRESULT CALLBACK
MouseLLHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
39 results
[test_no
].ll_hook_called
++;
40 return CallNextHookEx(hMouseHookLL
, nCode
, wParam
, lParam
);
43 LRESULT CALLBACK
MouseHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
45 results
[test_no
].hook_called
++;
46 return CallNextHookEx(hMouseHook
, nCode
, wParam
, lParam
);
49 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
51 if(msg
== WM_MOUSEMOVE
)
52 results
[test_no
].mouse_move_called
++;
54 return DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
57 static HWND
CreateTestWindow()
61 HANDLE hInstance
= GetModuleHandleA( NULL
);
64 wclass
.lpszClassName
= "MouseInputTestClass";
65 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
66 wclass
.lpfnWndProc
= WndProc
;
67 wclass
.hInstance
= hInstance
;
68 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
69 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
70 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
71 wclass
.lpszMenuName
= 0;
72 wclass
.cbClsExtra
= 0;
73 wclass
.cbWndExtra
= 0;
74 RegisterClassA( &wclass
);
75 /* create the test window that will receive the keystrokes */
76 hWndTest
= CreateWindowA( wclass
.lpszClassName
, "MouseInputTestTest",
77 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
78 NULL
, NULL
, hInstance
, NULL
);
80 ShowWindow( hWndTest
, SW_SHOWMAXIMIZED
);
81 SetWindowPos( hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
82 SetForegroundWindow( hWndTest
);
83 UpdateWindow( hWndTest
);
86 /* flush pending messages */
87 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
92 void Test_SetCursorPos()
98 hMouseHookLL
= SetWindowsHookEx(WH_MOUSE_LL
, MouseLLHookProc
, GetModuleHandleA( NULL
), 0);
99 hMouseHook
= SetWindowsHookExW(WH_MOUSE
, MouseHookProc
, GetModuleHandleW( NULL
), GetCurrentThreadId());
100 ok(hMouseHook
!=NULL
,"failed to set hook\n");
101 ok(hMouseHookLL
!=NULL
,"failed to set hook\n");
105 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
108 mouse_event(MOUSEEVENTF_MOVE
, 2,2, 0,0);
109 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
111 hwnd
= CreateTestWindow();
116 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
119 mouse_event(MOUSEEVENTF_MOVE
, 100,100, 0,0);
120 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
125 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
129 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
131 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
134 mouse_event(MOUSEEVENTF_MOVE
, 50,50, 0,0);
135 mouse_event(MOUSEEVENTF_MOVE
, 60,60, 0,0);
136 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
139 mouse_event(MOUSEEVENTF_MOVE
, 50,50, 0,0);
140 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
141 mouse_event(MOUSEEVENTF_MOVE
, 60,60, 0,0);
142 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
144 for(i
= 0; i
< 8; i
++)
146 #define TEST(s,x,y) ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
147 TEST("WH_MOUSE_LL", info
[i
].ll_hook_called
, results
[i
].ll_hook_called
);
148 /* WH_MOUSE results vary greatly among windows versions */
149 //TEST("WH_MOUSE", info[i].hook_called, results[i].hook_called);
150 TEST("WM_MOUSEMOVE", info
[i
].mouse_move_called
, results
[i
].mouse_move_called
);
156 UnhookWindowsHookEx (hMouseHook
);
157 UnhookWindowsHookEx (hMouseHookLL
);
161 void Test_DesktopAccess()
163 HDESK hDesk
, hDeskInitial
;
164 POINT curPoint
, initialPoint
;
167 hDeskInitial
= GetThreadDesktop(GetCurrentThreadId());
168 ok(hDeskInitial
!= NULL
, "Failed to retrieve the initial desktop\n");
170 ret
= GetCursorPos(&initialPoint
);
171 ok(ret
== TRUE
, "GetCursorPos should succed\n");
173 hDesk
= CreateDesktopW(L
"testDesktop", NULL
, NULL
, 0, 0x01ff, NULL
);
174 ok(hDesk
!= 0, "Failed to create a new desktop\n");
175 SetThreadDesktop(hDesk
);
176 ok(GetThreadDesktop(GetCurrentThreadId()) == hDesk
, "SetThreadDesktop had no effect\n");
178 SetLastError(0xdeadbeef);
180 ret
= GetCursorPos(&curPoint
);
181 ok(ret
== FALSE
, "GetCursorPos should fail\n");
183 ok(GetLastError() == ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED got 0x%lu\n", GetLastError());
184 SetLastError(0xdeadbeef);
186 ret
= SetCursorPos(2,2);
187 ok(ret
== FALSE
, "SetCursorPos should fail\n");
189 ok(GetLastError() == 0xdeadbeef, "Wrong last error, got 0x%lu\n", GetLastError());
191 ret
= GetCursorPos(&curPoint
);
192 ok(ret
== FALSE
, "GetCursorPos should fail\n");
194 SetThreadDesktop(hDeskInitial
);
196 ret
= GetCursorPos(&curPoint
);
197 ok(ret
== TRUE
, "GetCursorPos should succed\n");
198 ok(curPoint
.x
== initialPoint
.x
&& curPoint
.y
== initialPoint
.y
, "Mouse position changed\n");
201 START_TEST(SetCursorPos
)
203 Test_DesktopAccess();