8e429fa92c47808d80b6dc1dc05d4e0855bd58e3
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 memset(results
, sizeof(results
), 0);
100 hMouseHookLL
= SetWindowsHookEx(WH_MOUSE_LL
, MouseLLHookProc
, GetModuleHandleA( NULL
), 0);
101 hMouseHook
= SetWindowsHookExW(WH_MOUSE
, MouseHookProc
, GetModuleHandleW( NULL
), GetCurrentThreadId());
102 ok(hMouseHook
!=NULL
,"failed to set hook\n");
103 ok(hMouseHookLL
!=NULL
,"failed to set hook\n");
107 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
110 mouse_event(MOUSEEVENTF_MOVE
, 2,2, 0,0);
111 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
113 hwnd
= CreateTestWindow();
118 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
121 mouse_event(MOUSEEVENTF_MOVE
, 100,100, 0,0);
122 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
127 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
131 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
133 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
136 mouse_event(MOUSEEVENTF_MOVE
, 50,50, 0,0);
137 mouse_event(MOUSEEVENTF_MOVE
, 60,60, 0,0);
138 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
141 mouse_event(MOUSEEVENTF_MOVE
, 50,50, 0,0);
142 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
143 mouse_event(MOUSEEVENTF_MOVE
, 60,60, 0,0);
144 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
146 for(i
= 0; i
< 8; i
++)
148 #define TEST(s,x,y) ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
149 TEST("WH_MOUSE_LL", info
[i
].ll_hook_called
, results
[i
].ll_hook_called
);
150 /* WH_MOUSE results vary greatly among windows versions */
151 //TEST("WH_MOUSE", info[i].hook_called, results[i].hook_called);
152 TEST("WM_MOUSEMOVE", info
[i
].mouse_move_called
, results
[i
].mouse_move_called
);
158 UnhookWindowsHookEx (hMouseHook
);
159 UnhookWindowsHookEx (hMouseHookLL
);
163 void Test_DesktopAccess()
165 HDESK hDesk
, hDeskInitial
;
166 POINT curPoint
, initialPoint
;
169 hDeskInitial
= GetThreadDesktop(GetCurrentThreadId());
170 ok(hDeskInitial
!= NULL
, "Failed to retrieve the initial desktop\n");
172 ret
= GetCursorPos(&initialPoint
);
173 ok(ret
== TRUE
, "GetCursorPos should succed\n");
175 hDesk
= CreateDesktopW(L
"testDesktop", NULL
, NULL
, 0, 0x01ff, NULL
);
176 ok(hDesk
!= 0, "Failed to create a new desktop\n");
177 SetThreadDesktop(hDesk
);
178 ok(GetThreadDesktop(GetCurrentThreadId()) == hDesk
, "SetThreadDesktop had no effect\n");
180 SetLastError(0xdeadbeef);
182 ret
= GetCursorPos(&curPoint
);
183 ok(ret
== FALSE
, "GetCursorPos should fail\n");
185 ok(GetLastError() == ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED got 0x%lu\n", GetLastError());
186 SetLastError(0xdeadbeef);
188 ret
= SetCursorPos(2,2);
189 ok(ret
== FALSE
, "SetCursorPos should fail\n");
191 ok(GetLastError() == 0xdeadbeef, "Wrong last error, got 0x%lu\n", GetLastError());
193 ret
= GetCursorPos(&curPoint
);
194 ok(ret
== FALSE
, "GetCursorPos should fail\n");
196 SetThreadDesktop(hDeskInitial
);
198 ret
= GetCursorPos(&curPoint
);
199 ok(ret
== TRUE
, "GetCursorPos should succed\n");
200 ok(curPoint
.x
== initialPoint
.x
&& curPoint
.y
== initialPoint
.y
, "Mouse position changed\n");
203 START_TEST(SetCursorPos
)
205 Test_DesktopAccess();