openMSX
Keys_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2#include "Keys.hh"
3
4using namespace openmsx::Keys;
5
6static void test(const std::string& name1, KeyCode code1, bool canonical)
7{
8 std::string name2 = getName(code1);
9 if (canonical) {
10 CHECK(name2 == name1);
11 }
12
13 KeyCode code2 = getCode(name1);
14 CHECK(code2 == code1);
15
16 std::string name3 = getName(code2);
17 CHECK(name3 == name2);
18
19 KeyCode code3 = getCode(name2);
20 CHECK(code3 == code2);
21}
22
23TEST_CASE("Keys")
24{
25 test("P", K_P, true);
26 test("p", K_P, false);
27 test("1", K_1, true);
28 test("z", K_Z, false);
29 test("AT", K_AT, true);
30 test("Hash", K_HASH, false);
31 test("slash", K_SLASH, false);
32 test("EXCLAIM", K_EXCLAIM, true);
33 test("PeRiOd", K_PERIOD, false);
34 test("CARET", K_CARET, true);
35 test("delete", K_DELETE, false);
36 test("KP7", K_KP7, true);
37 test("KP_ENTER", K_KP_ENTER, true);
38 test("up", K_UP, false);
39 test("End", K_END, false);
40 test("pageup", K_PAGEUP, false);
41 test("PAGEDOWN", K_PAGEDOWN, true);
42 test("F8", K_F8, true);
43 test("RCTRL", K_RCTRL, true);
44
45 test("P+SHIFT", combine(K_P, KM_SHIFT), true);
46 test("q,shift", combine(K_Q, KM_SHIFT), false);
47 test("R/shift", combine(K_R, KM_SHIFT), false);
48 test("ctrl+c", combine(K_C, KM_CTRL), false);
49 test("ALT/E", combine(K_E, KM_ALT), false);
50 test("E+ALT", combine(K_E, KM_ALT), true);
51 test("5,release", combine(K_5, KD_RELEASE), false);
52}
void test(const IterableBitSet< N > &s, std::initializer_list< size_t > list)
TEST_CASE("Keys")
Definition: Keys_test.cc:23
CHECK(m3==m3)
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
Definition: Keys.hh:234
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
@ K_EXCLAIM
Definition: Keys.hh:38
@ KD_RELEASE
Definition: Keys.hh:212
@ K_KP_ENTER
Definition: Keys.hh:120
@ K_PERIOD
Definition: Keys.hh:50
@ K_PAGEDOWN
Definition: Keys.hh:132
KeyCode getCode(string_view name)
Translate key name to key code.
Definition: Keys.cc:330
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730