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 <x86corez@gmail.com> 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 } 64