backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virkeycodetest.c
blob963e9e09773a8f42477dae823e08b6ac216a118b
1 /*
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/>.
19 #include <config.h>
22 #include "testutils.h"
24 #include "virkeycode.h"
25 #include "virutil.h"
26 #include "virerror.h"
27 #include "viralloc.h"
28 #include "virlog.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)
38 int ret = -1;
39 int got;
41 #define TRANSLATE(from, to, val, want) \
42 do { \
43 if ((got = virKeycodeValueTranslate(VIR_KEYCODE_SET_##from, \
44 VIR_KEYCODE_SET_##to, \
45 val)) != want) { \
46 fprintf(stderr, "Translating %d from %s to %s, got %d want %d\n", \
47 val, #from, #to, got, want); \
48 goto cleanup; \
49 } \
50 } while (0)
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);
61 #undef TRANSLATE
63 ret = 0;
64 cleanup:
65 return ret;
69 static int testKeycodeStrings(const void *data ATTRIBUTE_UNUSED)
71 int ret = -1;
72 int got;
74 #define TRANSLATE(from, str, want) \
75 do { \
76 if ((got = virKeycodeValueFromString(VIR_KEYCODE_SET_##from, \
77 str)) != want) { \
78 fprintf(stderr, "Converting %s from %s, got %d want %d\n", \
79 str, #from, got, want); \
80 goto cleanup; \
81 } \
82 } while (0)
84 TRANSLATE(LINUX, "KEY_DELETE", 111);
85 TRANSLATE(LINUX, "KEY_RFKILL", 524);
86 TRANSLATE(LINUX, "KEY_WIBBLE",
87 -1);
88 TRANSLATE(OSX, "Function", 0x3f);
89 TRANSLATE(WIN32, "VK_UP", 0x26);
91 #undef TRANSLATE
93 ret = 0;
94 cleanup:
95 return ret;
98 static int
99 mymain(void)
101 int ret = 0;
103 if (virTestRun("Keycode mapping ", testKeycodeMapping, NULL) < 0)
104 ret = -1;
105 if (virTestRun("Keycode strings ", testKeycodeStrings, NULL) < 0)
106 ret = -1;
108 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
111 VIR_TEST_MAIN(mymain)