openMSX
Keys_test.cc
Go to the documentation of this file.
1 #include "catch.hpp"
2 #include "Keys.hh"
3 
4 using namespace openmsx::Keys;
5 
6 static 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 
23 TEST_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 }
openmsx::Keys::K_R
Definition: Keys.hh:92
openmsx::Keys::K_EXCLAIM
Definition: Keys.hh:37
TEST_CASE
TEST_CASE("Keys")
Definition: Keys_test.cc:23
openmsx::Keys::K_Q
Definition: Keys.hh:91
openmsx::Keys::K_Z
Definition: Keys.hh:100
CHECK
CHECK(m3==m3)
openmsx::Keys::K_C
Definition: Keys.hh:77
openmsx::Keys::K_5
Definition: Keys.hh:56
openmsx::Keys::K_CARET
Definition: Keys.hh:72
openmsx::Keys::combine
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
Definition: Keys.hh:231
openmsx::Keys::K_RCTRL
Definition: Keys.hh:165
openmsx::Keys::K_P
Definition: Keys.hh:90
openmsx::Keys
Definition: Keys.cc:10
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
openmsx::Keys::KM_ALT
Definition: Keys.hh:205
openmsx::Keys::getCode
KeyCode getCode(string_view name)
Definition: Keys.cc:341
openmsx::Keys::K_PERIOD
Definition: Keys.hh:49
openmsx::Keys::KM_CTRL
Definition: Keys.hh:204
openmsx::Keys::K_DELETE
Definition: Keys.hh:101
Keys.hh
openmsx::Keys::K_AT
Definition: Keys.hh:67
openmsx::Keys::K_F8
Definition: Keys.hh:141
openmsx::Keys::K_KP_ENTER
Definition: Keys.hh:119
openmsx::Keys::KM_SHIFT
Definition: Keys.hh:203
openmsx::Keys::K_HASH
Definition: Keys.hh:39
openmsx::Keys::K_UP
Definition: Keys.hh:123
openmsx::Keys::K_KP7
Definition: Keys.hh:111
openmsx::Keys::K_SLASH
Definition: Keys.hh:50
openmsx::Keys::KeyCode
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:25
openmsx::Keys::K_PAGEDOWN
Definition: Keys.hh:131
openmsx::Keys::KD_RELEASE
Definition: Keys.hh:211
openmsx::Keys::K_PAGEUP
Definition: Keys.hh:130
openmsx::Keys::K_1
Definition: Keys.hh:52
openmsx::Keys::K_END
Definition: Keys.hh:129
openmsx::Keys::K_E
Definition: Keys.hh:79