2 * Copyright (C) 2013 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; If not, see
16 * <http://www.gnu.org/licenses/>.
22 #include "testutils.h"
24 #include "virkeycode.h"
30 #include "virlockspace.h"
32 #define VIR_FROM_THIS VIR_FROM_NONE
34 VIR_LOG_INIT("tests.keycodetest");
36 static int testKeycodeMapping(const void *data ATTRIBUTE_UNUSED
)
41 #define TRANSLATE(from, to, val, want) \
43 if ((got = virKeycodeValueTranslate(VIR_KEYCODE_SET_##from, \
44 VIR_KEYCODE_SET_##to, \
46 fprintf(stderr, "Translating %d from %s to %s, got %d want %d\n", \
47 val, #from, #to, got, want); \
52 TRANSLATE(LINUX
, LINUX
, 111, 111);
53 TRANSLATE(LINUX
, USB
, 111, 76);
54 TRANSLATE(LINUX
, QNUM
, 88, 88);
55 TRANSLATE(LINUX
, QNUM
, 160, 163);
56 TRANSLATE(ATSET2
, ATSET3
, 131, 55);
57 TRANSLATE(OSX
, WIN32
, 90, 131);
58 TRANSLATE(OSX
, ATSET1
, 90, 90);
59 TRANSLATE(OSX
, ATSET1
, 3200, -1);
69 static int testKeycodeStrings(const void *data ATTRIBUTE_UNUSED
)
74 #define TRANSLATE(from, str, want) \
76 if ((got = virKeycodeValueFromString(VIR_KEYCODE_SET_##from, \
78 fprintf(stderr, "Converting %s from %s, got %d want %d\n", \
79 str, #from, got, want); \
84 TRANSLATE(LINUX
, "KEY_DELETE", 111);
85 TRANSLATE(LINUX
, "KEY_RFKILL", 524);
86 TRANSLATE(LINUX
, "KEY_WIBBLE",
88 TRANSLATE(OSX
, "Function", 0x3f);
89 TRANSLATE(WIN32
, "VK_UP", 0x26);
103 if (virTestRun("Keycode mapping ", testKeycodeMapping
, NULL
) < 0)
105 if (virTestRun("Keycode strings ", testKeycodeStrings
, NULL
) < 0)
108 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
111 VIR_TEST_MAIN(mymain
)