ReactOS  0.4.13-dev-257-gfabbd7c
SetCursorPos.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for SetCursorPos
5  * PROGRAMMERS: Giannis Adamopoulos
6  */
7 
8 #include "precomp.h"
9 
11 
12 struct _test_info
13 {
17 };
18 
19 struct _test_info info[] = { {0,0,0}, /* SetCursorPos without a window */
20  {1,1,0}, /* mouse_event without a window */
21  {0,1,1}, /* SetCursorPos with a window */
22  {1,1,1}, /* mouse_event with a window */
23  {0,1,1}, /* multiple SetCursorPos with a window with coalescing */
24  {0,2,2}, /* multiple SetCursorPos with a window without coalescing */
25  {2,1,1}, /* multiple mouse_event with a window with coalescing */
26  {2,2,2}, /* multiple mouse_event with a window without coalescing */
27  };
28 
29 struct _test_info results[8];
30 int test_no = 0;
31 
32 
34 {
35  results[test_no].ll_hook_called++;
36  return CallNextHookEx(hMouseHookLL, nCode, wParam, lParam);
37 }
38 
40 {
41  results[test_no].hook_called++;
42  return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
43 }
44 
46 {
47  if(msg == WM_MOUSEMOVE)
48  results[test_no].mouse_move_called++;
49 
50  return DefWindowProcA( hWnd, msg, wParam, lParam );
51 }
52 
54 {
55  MSG msg;
56  WNDCLASSA wclass;
58  HWND hWndTest;
59 
60  wclass.lpszClassName = "MouseInputTestClass";
61  wclass.style = CS_HREDRAW | CS_VREDRAW;
62  wclass.lpfnWndProc = WndProc;
63  wclass.hInstance = hInstance;
64  wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
65  wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
66  wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
67  wclass.lpszMenuName = 0;
68  wclass.cbClsExtra = 0;
69  wclass.cbWndExtra = 0;
70  RegisterClassA( &wclass );
71  /* create the test window that will receive the keystrokes */
72  hWndTest = CreateWindowA( wclass.lpszClassName, "MouseInputTestTest",
73  WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
74  NULL, NULL, hInstance, NULL);
75  assert( hWndTest );
81 
82  /* flush pending messages */
83  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
84 
85  return hWndTest;
86 }
87 
89 {
90  HWND hwnd;
91  MSG msg;
92  int i;
93 
96  ok(hMouseHook!=NULL,"failed to set hook\n");
97  ok(hMouseHookLL!=NULL,"failed to set hook\n");
98 
99  test_no = 0;
100  SetCursorPos(1,1);
101  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
102 
103  test_no = 1;
104  mouse_event(MOUSEEVENTF_MOVE, 2,2, 0,0);
105  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
106 
108  SetCapture(hwnd);
109 
110  test_no = 2;
111  SetCursorPos(50,50);
112  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
113 
114  test_no = 3;
115  mouse_event(MOUSEEVENTF_MOVE, 100,100, 0,0);
116  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
117 
118  test_no = 4;
119  SetCursorPos(50,50);
120  SetCursorPos(60,60);
121  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
122 
123  test_no = 5;
124  SetCursorPos(50,50);
125  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
126  SetCursorPos(60,60);
127  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
128 
129  test_no = 6;
130  mouse_event(MOUSEEVENTF_MOVE, 50,50, 0,0);
131  mouse_event(MOUSEEVENTF_MOVE, 60,60, 0,0);
132  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
133 
134  test_no = 7;
135  mouse_event(MOUSEEVENTF_MOVE, 50,50, 0,0);
136  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
137  mouse_event(MOUSEEVENTF_MOVE, 60,60, 0,0);
138  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
139 
140  for(i = 0; i< 8; i++)
141  {
142 #define TEST(s,x,y) ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
143  TEST("WH_MOUSE_LL", info[i].ll_hook_called, results[i].ll_hook_called);
144  /* WH_MOUSE results vary greatly among windows versions */
145  //TEST("WH_MOUSE", info[i].hook_called, results[i].hook_called);
146  TEST("WM_MOUSEMOVE", info[i].mouse_move_called, results[i].mouse_move_called);
147  }
148 
149  SetCapture(NULL);
151 
154 
155 }
156 
158 {
159  HDESK hDesk, hDeskInitial;
160  POINT curPoint, initialPoint;
161  BOOL ret;
162 
163  hDeskInitial = GetThreadDesktop(GetCurrentThreadId());
164  ok(hDeskInitial != NULL, "Failed to retrieve the initial desktop\n");
165 
166  ret = GetCursorPos(&initialPoint);
167  ok(ret == TRUE, "GetCursorPos should succed\n");
168 
169  hDesk = CreateDesktopW(L"testDesktop", NULL, NULL, 0, 0x01ff, NULL);
170  ok(hDesk != 0, "Failed to create a new desktop\n");
171  SetThreadDesktop(hDesk);
172  ok(GetThreadDesktop(GetCurrentThreadId()) == hDesk, "SetThreadDesktop had no effect\n");
173 
174  SetLastError(0xdeadbeef);
175 
176  ret = GetCursorPos(&curPoint);
177  ok(ret == FALSE, "GetCursorPos should fail\n");
178 
179  ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED got 0x%lx\n", GetLastError());
180  SetLastError(0xdeadbeef);
181 
182  ret = SetCursorPos(2,2);
183  ok(ret == FALSE, "SetCursorPos should fail\n");
184 
185  ok(GetLastError() == 0xdeadbeef, "Wrong last error, got 0x%lx\n", GetLastError());
186 
187  ret = GetCursorPos(&curPoint);
188  ok(ret == FALSE, "GetCursorPos should fail\n");
189 
190  SetThreadDesktop(hDeskInitial);
191 
192  ret = GetCursorPos(&curPoint);
193  ok(ret == TRUE, "GetCursorPos should succed\n");
194  ok(curPoint.x == initialPoint.x && curPoint.y == initialPoint.y, "Mouse position changed\n");
195 }
196 
198 {
201 }
int test_no
Definition: SetCursorPos.c:30
#define WH_MOUSE
Definition: winuser.h:37
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5696
#define TRUE
Definition: types.h:120
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
HHOOK hMouseHookLL
Definition: SetCursorPos.c:10
#define SW_SHOWMAXIMIZED
Definition: winuser.h:767
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
int mouse_move_called
Definition: SetCursorPos.c:16
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
HDESK WINAPI GetThreadDesktop(_In_ DWORD)
int cbClsExtra
Definition: winuser.h:3118
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3124
#define HWND_TOPMOST
Definition: winuser.h:1194
HWND WINAPI SetFocus(_In_opt_ HWND)
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3123
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
BOOL WINAPI DestroyWindow(_In_ HWND)
#define COLOR_WINDOW
Definition: winuser.h:908
LRESULT CALLBACK MouseLLHookProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: SetCursorPos.c:33
WPARAM wParam
Definition: combotst.c:138
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2029
BOOL WINAPI SetThreadDesktop(_In_ HDESK)
#define WH_MOUSE_LL
Definition: winuser.h:44
int cbWndExtra
Definition: winuser.h:3119
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
int ll_hook_called
Definition: SetCursorPos.c:14
#define ok(value,...)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4184
START_TEST(SetCursorPos)
Definition: SetCursorPos.c:197
HCURSOR hCursor
Definition: winuser.h:3122
#define CW_USEDEFAULT
Definition: winuser.h:225
void WINAPI mouse_event(_In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ ULONG_PTR)
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:420
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: SetCursorPos.c:39
static HWND hWndTest
Definition: input.c:68
#define CS_VREDRAW
Definition: winuser.h:653
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2627
#define SetWindowsHookEx
Definition: winuser.h:5722
void Test_SetCursorPos()
Definition: SetCursorPos.c:88
#define SetLastError(x)
Definition: compat.h:409
struct _test_info results[8]
Definition: SetCursorPos.c:29
int ret
static const WCHAR L[]
Definition: oid.c:1250
HHOOK hMouseHook
Definition: SetCursorPos.c:10
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define TEST(s, x, y)
LPCSTR lpszClassName
Definition: winuser.h:3125
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: SetCursorPos.c:45
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
UINT style
Definition: winuser.h:3116
#define SWP_NOSIZE
Definition: winuser.h:1230
HWND WINAPI SetCapture(_In_ HWND hWnd)
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
HINSTANCE hInstance
Definition: winuser.h:3120
#define MOUSEEVENTF_MOVE
Definition: winuser.h:1169
unsigned int UINT
Definition: ndis.h:50
#define WM_MOUSEMOVE
Definition: winuser.h:1751
int hook_called
Definition: SetCursorPos.c:15
WNDPROC lpfnWndProc
Definition: winuser.h:3117
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
HHOOK WINAPI SetWindowsHookExW(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
static HWND CreateTestWindow()
Definition: SetCursorPos.c:53
void Test_DesktopAccess()
Definition: SetCursorPos.c:157
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define SWP_NOMOVE
Definition: winuser.h:1229
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1182
HDESK WINAPI CreateDesktopW(LPCWSTR lpszDesktop, LPCWSTR lpszDevice, LPDEVMODEW pDevmode, DWORD dwFlags, ACCESS_MASK dwDesiredAccess, LPSECURITY_ATTRIBUTES lpsa)
Definition: desktop.c:473
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HICON hIcon
Definition: winuser.h:3121