Author: gadamopoulos
Date: Sat Apr 9 19:12:49 2011
New Revision: 51304
URL:
http://svn.reactos.org/svn/reactos?rev=51304&view=rev
Log:
add some tests for GetKeyState and SetCursorPos
Added:
trunk/rostests/apitests/user32/GetKeyState.c (with props)
trunk/rostests/apitests/user32/SetCursorPos.c (with props)
Modified:
trunk/rostests/apitests/user32/testlist.c
trunk/rostests/apitests/user32/user32_apitest.rbuild
Added: trunk/rostests/apitests/user32/GetKeyState.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/user32/GetKeySta…
==============================================================================
--- trunk/rostests/apitests/user32/GetKeyState.c (added)
+++ trunk/rostests/apitests/user32/GetKeyState.c [iso-8859-1] Sat Apr 9 19:12:49 2011
@@ -1,0 +1,127 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: GPL - See COPYING in the top level directory
+ * PURPOSE: Test for GetKeyState
+ * PROGRAMMERS: Giannis Adamopoulos
+ */
+
+#include <stdio.h>
+#include <wine/test.h>
+#include <windows.h>
+#include <assert.h>
+
+HHOOK hKbdHook, hKbdLLHook;
+
+
+LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam)
+{
+ BOOL pressed = !(lParam & (1<<31));
+ BOOL altPressed = lParam & (1<<29);
+
+ if(pressed)
+ {
+ ok(altPressed,"\n");
+ ok((GetKeyState(VK_MENU) & 0x8000), "Alt should not be pressed\n");
+ }
+ else
+ {
+ ok(!altPressed,"\n");
+ ok(!(GetKeyState(VK_MENU) & 0x8000), "Alt should be pressed\n");
+ }
+
+ return CallNextHookEx(hKbdHook, code, wParam, lParam);
+}
+
+LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+ PKBDLLHOOKSTRUCT pLLHook = (PKBDLLHOOKSTRUCT)lParam;
+
+ if(wParam == WM_SYSKEYDOWN)
+ {
+ ok(pLLHook->flags & LLKHF_ALTDOWN,"Didn't get LLKHF_ALTDOWN
flag\n");
+ ok((GetAsyncKeyState (VK_MENU) & 0x8000), "Alt should not be pressed in global
kbd status\n");
+ ok(!(GetKeyState(VK_MENU) & 0x8000), "Alt should not be pressed in queue
state\n");
+ }
+ else if(wParam == WM_SYSKEYUP)
+ {
+ ok(!(pLLHook->flags & LLKHF_ALTDOWN),"got LLKHF_ALTDOWN flag\n");
+ ok(!(GetAsyncKeyState (VK_MENU) & 0x8000), "Alt should not be pressed in
global kbd status\n");
+ ok((GetKeyState(VK_MENU) & 0x8000), "Alt should be pressed in queue
state\n");
+ }
+
+ return CallNextHookEx(hKbdLLHook, nCode, wParam, lParam);
+}
+
+static LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
+{
+ return DefWindowProcA( hWnd, msg, wParam, lParam );
+}
+
+static HWND CreateTestWindow()
+{
+ MSG msg;
+ WNDCLASSA wclass;
+ HANDLE hInstance = GetModuleHandleA( NULL );
+ HWND hWndTest;
+
+ wclass.lpszClassName = "InputSysKeyTestClass";
+ wclass.style = CS_HREDRAW | CS_VREDRAW;
+ wclass.lpfnWndProc = WndProc;
+ wclass.hInstance = hInstance;
+ wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
+ wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
+ wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
+ wclass.lpszMenuName = 0;
+ wclass.cbClsExtra = 0;
+ wclass.cbWndExtra = 0;
+ RegisterClassA( &wclass );
+ /* create the test window that will receive the keystrokes */
+ hWndTest = CreateWindowA( wclass.lpszClassName, "InputSysKeyTest",
+ WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
+ NULL, NULL, hInstance, NULL);
+ assert( hWndTest );
+ ShowWindow( hWndTest, SW_SHOW);
+ SetWindowPos( hWndTest, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
+ SetForegroundWindow( hWndTest );
+ UpdateWindow( hWndTest);
+
+ /* flush pending messages */
+ while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
+
+ return hWndTest;
+}
+
+void Test_GetKeyState()
+{
+ HWND hwnd;
+ MSG msg;
+
+ hwnd = CreateTestWindow();
+
+ hKbdHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, GetModuleHandleA( NULL ), 0);
+ hKbdLLHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandleA(
NULL ), 0);
+
+ ok(hKbdHook!=NULL," \n");
+ ok(hKbdLLHook!=NULL," \n");
+
+ keybd_event(VK_MENU, 0, 0,0);
+
+ while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
+
+ keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP,0);
+
+ //fixme this hangs the test
+ //while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessageA(
&msg );
+
+ DestroyWindow(hwnd);
+
+ while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
+
+ UnhookWindowsHookEx (hKbdHook);
+ UnhookWindowsHookEx (hKbdLLHook);
+}
+
+START_TEST(GetKeyState)
+{
+ Test_GetKeyState();
+}
Propchange: trunk/rostests/apitests/user32/GetKeyState.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/user32/SetCursorPos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/user32/SetCursor…
==============================================================================
--- trunk/rostests/apitests/user32/SetCursorPos.c (added)
+++ trunk/rostests/apitests/user32/SetCursorPos.c [iso-8859-1] Sat Apr 9 19:12:49 2011
@@ -1,0 +1,41 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: GPL - See COPYING in the top level directory
+ * PURPOSE: Test for SetCursorPos
+ * PROGRAMMERS: Giannis Adamopoulos
+ */
+
+#include <stdio.h>
+#include <wine/test.h>
+#include <windows.h>
+#include <assert.h>
+
+HHOOK hMouseHook;
+int hook_calls = 0;
+
+LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+ hook_calls++;
+ return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
+}
+
+void Test_SetCursorPos()
+{
+ hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, GetModuleHandleA( NULL ),
0);
+ ok(hMouseHook!=NULL,"failed to set hook\n");
+
+ /* try SetCursorPos */
+ SetCursorPos(0,0);
+ ok (hook_calls == 0, "hooks shouldn't be called\n");
+
+ /* try mouse_event with MOUSEEVENTF_MOVE*/
+ mouse_event(MOUSEEVENTF_MOVE, 100,100, 0,0);
+ ok (hook_calls == 1, "hooks should have been called\n");
+
+ UnhookWindowsHookEx (hMouseHook);
+}
+
+START_TEST(SetCursorPos)
+{
+ Test_SetCursorPos();
+}
Propchange: trunk/rostests/apitests/user32/SetCursorPos.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rostests/apitests/user32/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/user32/testlist.…
==============================================================================
--- trunk/rostests/apitests/user32/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/user32/testlist.c [iso-8859-1] Sat Apr 9 19:12:49 2011
@@ -13,6 +13,8 @@
extern void func_GetIconInfo(void);
extern void func_GetPeekMessage(void);
extern void func_DeferWindowPos(void);
+extern void func_GetKeyState(void);
+extern void func_SetCursorPos(void);
const struct test winetest_testlist[] =
{
@@ -24,7 +26,8 @@
{ "GetIconInfo", func_GetIconInfo },
{ "GetPeekMessage", func_GetPeekMessage },
{ "DeferWindowPos", func_DeferWindowPos },
-
+ { "GetKeyState", func_GetKeyState },
+ { "SetCursorPos", func_SetCursorPos },
{ 0, 0 }
};
Modified: trunk/rostests/apitests/user32/user32_apitest.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/user32/user32_ap…
==============================================================================
--- trunk/rostests/apitests/user32/user32_apitest.rbuild [iso-8859-1] (original)
+++ trunk/rostests/apitests/user32/user32_apitest.rbuild [iso-8859-1] Sat Apr 9 19:12:49
2011
@@ -10,6 +10,7 @@
<file>testlist.c</file>
<file>user32_apitest.rc</file>
+ <file>GetKeyState.c</file>
<file>InitializeLpkHooks.c</file>
<file>RealGetWindowClass.c</file>
<file>ScrollDC.c</file>
@@ -18,6 +19,7 @@
<file>GetIconInfo.c</file>
<file>GetPeekMessage.c</file>
<file>DeferWindowPos.c</file>
+ <file>SetCursorPos.c</file>
</module>
</group>