2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetCursorPos
5 * PROGRAMMERS: Giannis Adamopoulos
13 HHOOK hMouseHookLL
, hMouseHook
;
19 int mouse_move_called
;
22 struct _test_info info
[] = { {0,0,0}, /* SetCursorPos without a window */
23 {1,2,0}, /* mouse_event without a window */
24 {0,1,1}, /* SetCursorPos with a window */
25 {1,1,1}, /* mouse_event with a window */
26 {0,1,1}, /* multiple SetCursorPos with a window with coalescing */
27 {0,2,2}, /* multiple SetCursorPos with a window without coalescing */
28 {2,1,1}, /* multiple mouse_event with a window with coalescing */
29 {2,2,2}, /* multiple mouse_event with a window without coalescing */
32 struct _test_info results
[8];
36 LRESULT CALLBACK
MouseLLHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
38 results
[test_no
].ll_hook_called
++;
39 return CallNextHookEx(hMouseHookLL
, nCode
, wParam
, lParam
);
42 LRESULT CALLBACK
MouseHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
44 results
[test_no
].hook_called
++;
45 return CallNextHookEx(hMouseHook
, nCode
, wParam
, lParam
);
48 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
50 if(msg
== WM_MOUSEMOVE
)
51 results
[test_no
].mouse_move_called
++;
53 return DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
56 static HWND
CreateTestWindow()
60 HANDLE hInstance
= GetModuleHandleA( NULL
);
63 wclass
.lpszClassName
= "MouseInputTestClass";
64 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
65 wclass
.lpfnWndProc
= WndProc
;
66 wclass
.hInstance
= hInstance
;
67 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
68 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
69 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
70 wclass
.lpszMenuName
= 0;
71 wclass
.cbClsExtra
= 0;
72 wclass
.cbWndExtra
= 0;
73 RegisterClassA( &wclass
);
74 /* create the test window that will receive the keystrokes */
75 hWndTest
= CreateWindowA( wclass
.lpszClassName
, "MouseInputTestTest",
76 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
77 NULL
, NULL
, hInstance
, NULL
);
79 ShowWindow( hWndTest
, SW_SHOWMAXIMIZED
);
80 SetWindowPos( hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
81 SetForegroundWindow( hWndTest
);
82 UpdateWindow( hWndTest
);
85 /* flush pending messages */
86 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
91 void Test_SetCursorPos()
97 memset(results
, sizeof(results
), 0);
99 hMouseHookLL
= SetWindowsHookEx(WH_MOUSE_LL
, MouseLLHookProc
, GetModuleHandleA( NULL
), 0);
100 hMouseHook
= SetWindowsHookEx(WH_MOUSE
, MouseHookProc
, GetModuleHandleA( NULL
), 0);
101 ok(hMouseHook
!=NULL
,"failed to set hook\n");
102 ok(hMouseHookLL
!=NULL
,"failed to set hook\n");
106 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
109 mouse_event(MOUSEEVENTF_MOVE
, 2,2, 0,0);
110 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
112 hwnd
= CreateTestWindow();
117 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
120 mouse_event(MOUSEEVENTF_MOVE
, 100,100, 0,0);
121 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
126 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
130 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
132 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
135 mouse_event(MOUSEEVENTF_MOVE
, 50,50, 0,0);
136 mouse_event(MOUSEEVENTF_MOVE
, 60,60, 0,0);
137 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
140 mouse_event(MOUSEEVENTF_MOVE
, 50,50, 0,0);
141 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
142 mouse_event(MOUSEEVENTF_MOVE
, 60,60, 0,0);
143 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
145 for(i
= 0; i
< 8; i
++)
147 #define TEST(s,x,y) ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
148 TEST("WH_MOUSE_LL", info
[i
].ll_hook_called
, results
[i
].ll_hook_called
);
149 /* WH_MOUSE results vary greatly among windows versions */
150 //TEST("WH_MOUSE", info[i].hook_called, results[i].hook_called);
151 TEST("WM_MOUSEMOVE", info
[i
].mouse_move_called
, results
[i
].mouse_move_called
);
157 UnhookWindowsHookEx (hMouseHook
);
158 UnhookWindowsHookEx (hMouseHookLL
);
162 START_TEST(SetCursorPos
)