summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/input/test_input_event_key.h56
1 files changed, 49 insertions, 7 deletions
diff --git a/tests/core/input/test_input_event_key.h b/tests/core/input/test_input_event_key.h
index 3317941fad..80918542ce 100644
--- a/tests/core/input/test_input_event_key.h
+++ b/tests/core/input/test_input_event_key.h
@@ -85,6 +85,16 @@ TEST_CASE("[InputEventKey] Key correctly stores and retrieves unicode") {
CHECK(key.get_unicode() != 'y');
}
+TEST_CASE("[InputEventKey] Key correctly stores and retrieves location") {
+ InputEventKey key;
+
+ CHECK(key.get_location() == KeyLocation::UNSPECIFIED);
+
+ key.set_location(KeyLocation::LEFT);
+ CHECK(key.get_location() == KeyLocation::LEFT);
+ CHECK(key.get_location() != KeyLocation::RIGHT);
+}
+
TEST_CASE("[InputEventKey] Key correctly stores and checks echo") {
InputEventKey key;
@@ -144,32 +154,36 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
TEST_CASE("[InputEventKey] Key correctly converts its state to a string representation") {
InputEventKey none_key;
- CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, pressed=false, echo=false");
+ CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, location=unspecified, pressed=false, echo=false");
// Set physical key to Escape.
none_key.set_physical_keycode(Key::ESCAPE);
- CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, pressed=false, echo=false");
+ CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, location=unspecified, pressed=false, echo=false");
InputEventKey key;
// Set physical to None, set keycode to Space.
key.set_keycode(Key::SPACE);
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=false, echo=false");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=unspecified, pressed=false, echo=false");
+
+ // Set location
+ key.set_location(KeyLocation::RIGHT);
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=false, echo=false");
// Set pressed to true.
key.set_pressed(true);
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=true, echo=false");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=true, echo=false");
// set echo to true.
key.set_echo(true);
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=true, echo=true");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=true, echo=true");
// Press Ctrl and Alt.
key.set_ctrl_pressed(true);
key.set_alt_pressed(true);
#ifdef MACOS_ENABLED
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Option, physical=false, pressed=true, echo=true");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Option, physical=false, location=right, pressed=true, echo=true");
#else
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Alt, physical=false, pressed=true, echo=true");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Alt, physical=false, location=right, pressed=true, echo=true");
#endif
}
@@ -291,6 +305,34 @@ TEST_CASE("[IsMatch] Keys are correctly matched") {
CHECK(key2.is_match(match, true) == true);
CHECK(key2.is_match(no_match, true) == false);
+
+ // Physical key with location.
+ InputEventKey key3;
+ key3.set_keycode(Key::NONE);
+ key3.set_physical_keycode(Key::SHIFT);
+
+ Ref<InputEventKey> loc_ref = key.create_reference(Key::NONE);
+
+ loc_ref->set_keycode(Key::SHIFT);
+ loc_ref->set_physical_keycode(Key::SHIFT);
+
+ CHECK(key3.is_match(loc_ref, false) == true);
+ key3.set_location(KeyLocation::UNSPECIFIED);
+ CHECK(key3.is_match(loc_ref, false) == true);
+
+ loc_ref->set_location(KeyLocation::LEFT);
+ CHECK(key3.is_match(loc_ref, false) == true);
+
+ key3.set_location(KeyLocation::LEFT);
+ CHECK(key3.is_match(loc_ref, false) == true);
+
+ key3.set_location(KeyLocation::RIGHT);
+ CHECK(key3.is_match(loc_ref, false) == false);
+
+ // Keycode key with location.
+ key3.set_physical_keycode(Key::NONE);
+ key3.set_keycode(Key::SHIFT);
+ CHECK(key3.is_match(loc_ref, false) == true);
}
} // namespace TestInputEventKey