Skip to content

Commit c1c1279

Browse files
committed
[USER32_APITEST] Add tests for MapVirtualKeyW
For @julcar. See PR reactos#4730 for details. CORE-17906
1 parent cd2d284 commit c1c1279

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

modules/rostests/apitests/user32/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ list(APPEND SOURCE
4848
SwitchToThisWindow.c
4949
SystemParametersInfo.c
5050
TrackMouseEvent.c
51+
VirtualKey.c
5152
WndProc.c
5253
wsprintf.c)
5354

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* PROJECT: ReactOS API tests
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4+
* PURPOSE: Tests for virtual keys
5+
* COPYRIGHT: Copyright 2022 Stanislav Motylkov <[email protected]>
6+
*/
7+
8+
#include "precomp.h"
9+
10+
UINT MapTypes[] = {
11+
MAPVK_VK_TO_VSC,
12+
MAPVK_VSC_TO_VK,
13+
MAPVK_VK_TO_CHAR,
14+
MAPVK_VSC_TO_VK_EX,
15+
#if (NTDDI_VERSION >= NTDDI_VISTA)
16+
MAPVK_VK_TO_VSC_EX,
17+
#endif
18+
};
19+
20+
struct
21+
{
22+
UINT VirtKey;
23+
UINT ScanToVirt;
24+
UINT ScanCode;
25+
} TestCodes[] = {
26+
{VK_TAB, 0, 15},
27+
{VK_RETURN, 0, 28},
28+
{VK_CONTROL, 0, 29},
29+
{VK_LCONTROL, VK_CONTROL, 29},
30+
{VK_RCONTROL, VK_CONTROL, 29},
31+
{VK_MENU, 0, 56},
32+
{VK_SPACE, 0, 57},
33+
};
34+
35+
static void testMapVirtualKey()
36+
{
37+
INT i;
38+
UINT vCode, vExpect = 0;
39+
40+
/* Make sure MapVirtualKeyW returns 0 in all cases when uCode == 0 */
41+
for (i = 0; i < _countof(MapTypes); i++)
42+
{
43+
vCode = MapVirtualKeyW(0, MapTypes[i]);
44+
ok(vCode == vExpect, "[%d] Returned %u, expected %u\n", i, vCode, vExpect);
45+
}
46+
47+
/* Test matching between virtual keys and scan codes */
48+
for (i = 0; i < _countof(TestCodes); i++)
49+
{
50+
vCode = MapVirtualKeyW(TestCodes[i].VirtKey, MAPVK_VK_TO_VSC);
51+
vExpect = TestCodes[i].ScanCode;
52+
ok(vCode == vExpect, "[%d] ScanCode = %u, expected %u\n", i, vCode, vExpect);
53+
54+
vCode = MapVirtualKeyW(TestCodes[i].ScanCode, MAPVK_VSC_TO_VK);
55+
vExpect = (TestCodes[i].ScanToVirt == 0 ? TestCodes[i].VirtKey : TestCodes[i].ScanToVirt);
56+
ok(vCode == vExpect, "[%d] VirtKey = %u, expected %u\n", i, vCode, vExpect);
57+
}
58+
}
59+
60+
START_TEST(VirtualKey)
61+
{
62+
testMapVirtualKey();
63+
}

modules/rostests/apitests/user32/testlist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern void func_ShowWindow(void);
5050
extern void func_SwitchToThisWindow(void);
5151
extern void func_SystemParametersInfo(void);
5252
extern void func_TrackMouseEvent(void);
53+
extern void func_VirtualKey(void);
5354
extern void func_WndProc(void);
5455
extern void func_wsprintf(void);
5556

@@ -102,6 +103,7 @@ const struct test winetest_testlist[] =
102103
{ "SwitchToThisWindow", func_SwitchToThisWindow },
103104
{ "SystemParametersInfo", func_SystemParametersInfo },
104105
{ "TrackMouseEvent", func_TrackMouseEvent },
106+
{ "VirtualKey", func_VirtualKey },
105107
{ "WndProc", func_WndProc },
106108
{ "wsprintfApi", func_wsprintf },
107109
{ 0, 0 }

0 commit comments

Comments
 (0)