From dff0ce1962317c0352a09b553104de032f750430 Mon Sep 17 00:00:00 2001 From: Ian Gaither Date: Mon, 14 Nov 2022 21:49:44 -0800 Subject: [PATCH 1/4] Initial InputEvent set of unit tests Covers all branches of non-virtual functions for all derivatives of the InputEvent class. --- tests/core/input/test_input_event.h | 114 ++++++++++++++++++++++++++++ tests/test_main.cpp | 1 + 2 files changed, 115 insertions(+) create mode 100644 tests/core/input/test_input_event.h diff --git a/tests/core/input/test_input_event.h b/tests/core/input/test_input_event.h new file mode 100644 index 000000000000..57b4a9f4fa3d --- /dev/null +++ b/tests/core/input/test_input_event.h @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* test_input_event_key.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TEST_INPUT_EVENT_H +#define TEST_INPUT_EVENT_H + +#include "core/input/input_event.h" +#include "core/input/input_map.h" + +#include "tests/test_macros.h" + +namespace TestInputEvent { + +typedef std::tuple< + InputEventWithModifiers, + InputEventKey, + InputEventMouse, + InputEventMouseButton, + InputEventMouseMotion, + InputEventJoypadMotion, + InputEventJoypadButton, + InputEventScreenTouch, + InputEventScreenDrag, + InputEventAction, + InputEventGesture, + InputEventPanGesture, + InputEventMIDI, + InputEventShortcut +> InputEventTypes; + +TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Event correctly changes and returns device", T, test_device) { + T event = T(); + + event.set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); + CHECK(event.get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE); + CHECK(event.get_device() != InputEvent::DEVICE_ID_INTERNAL); + + event.set_device(InputEvent::DEVICE_ID_INTERNAL); + CHECK(event.get_device() == InputEvent::DEVICE_ID_INTERNAL); + CHECK(event.get_device() != InputEvent::DEVICE_ID_TOUCH_MOUSE); +} +TEST_CASE_TEMPLATE_APPLY(test_device, InputEventTypes); + +TEST_CASE_TEMPLATE_DEFINE("[InputEvent] actions", T, test_actions) { + T event = T(); + InputMap inputMap = InputMap(); + + StringName testEventName("TestInputEvent"); + InputMap::get_singleton()->add_action(testEventName); + + SUBCASE("Action is present") { + CHECK(event.InputEvent::is_action(testEventName) == true); + CHECK(event.InputEvent::is_action(testEventName, true) == true); + } + + SUBCASE("Action has default pressed value") { + //default Action value is false + CHECK(event.is_action_pressed(testEventName) == false); + CHECK(event.is_action_pressed(testEventName, true) == false); + CHECK(event.is_action_pressed(testEventName, true, true) == false); + } + + SUBCASE("Action has default released value") { + //default Action value is true + CHECK(event.is_action_released(testEventName) == true); + CHECK(event.is_action_released(testEventName, true) == true); + } + + SUBCASE("Action has default strength value") { + //default Action value is 0.5f + CHECK(event.get_action_strength(testEventName) == 0.5f); + CHECK(event.get_action_strength(testEventName, true) == 0.5f); + } + + SUBCASE("Action has default strength value") { + //default Action value is 0.5f + CHECK(event.get_action_raw_strength(testEventName) == 0.5f); + CHECK(event.get_action_raw_strength(testEventName, true) == 0.5f); + } + + InputMap::get_singleton()->erase_action(testEventName); +} +TEST_CASE_TEMPLATE_APPLY(test_actions, InputEventTypes); + +} // namespace TestInputEvent + +#endif // TEST_INPUT_EVENT_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index d58c19ac3291..ad0ccab7db2f 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -30,6 +30,7 @@ #include "test_main.h" +#include "tests/core/input/test_input_event.h" #include "tests/core/input/test_input_event_key.h" #include "tests/core/input/test_shortcut.h" #include "tests/core/io/test_config_file.h" From 80b9f27b3328758beef0a22534d1431d4267ad1b Mon Sep 17 00:00:00 2001 From: Ian Gaither Date: Mon, 14 Nov 2022 22:22:32 -0800 Subject: [PATCH 2/4] Replaced spaces with tabs and added class specifiers to the non virtual function calls Cleaned up formatting issues and added class specifiers to hopefully resolve the macOS build issues. --- tests/core/input/test_input_event.h | 122 ++++++++++++++-------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/tests/core/input/test_input_event.h b/tests/core/input/test_input_event.h index 57b4a9f4fa3d..5818ae42c7fc 100644 --- a/tests/core/input/test_input_event.h +++ b/tests/core/input/test_input_event.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* test_input_event_key.h */ +/* test_input_event.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -39,73 +39,73 @@ namespace TestInputEvent { typedef std::tuple< - InputEventWithModifiers, - InputEventKey, - InputEventMouse, - InputEventMouseButton, - InputEventMouseMotion, - InputEventJoypadMotion, - InputEventJoypadButton, - InputEventScreenTouch, - InputEventScreenDrag, - InputEventAction, - InputEventGesture, - InputEventPanGesture, - InputEventMIDI, - InputEventShortcut -> InputEventTypes; + InputEventWithModifiers, + InputEventKey, + InputEventMouse, + InputEventMouseButton, + InputEventMouseMotion, + InputEventJoypadMotion, + InputEventJoypadButton, + InputEventScreenTouch, + InputEventScreenDrag, + InputEventAction, + InputEventGesture, + InputEventPanGesture, + InputEventMIDI, + InputEventShortcut + > InputEventTypes; TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Event correctly changes and returns device", T, test_device) { - T event = T(); + T event = T(); - event.set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); - CHECK(event.get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE); - CHECK(event.get_device() != InputEvent::DEVICE_ID_INTERNAL); + event.InputEvent::set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); + CHECK(event.InputEvent::get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE); + CHECK(event.InputEvent::get_device() != InputEvent::DEVICE_ID_INTERNAL); - event.set_device(InputEvent::DEVICE_ID_INTERNAL); - CHECK(event.get_device() == InputEvent::DEVICE_ID_INTERNAL); - CHECK(event.get_device() != InputEvent::DEVICE_ID_TOUCH_MOUSE); + event.set_device(InputEvent::DEVICE_ID_INTERNAL); + CHECK(event.InputEvent::get_device() == InputEvent::DEVICE_ID_INTERNAL); + CHECK(event.InputEvent::get_device() != InputEvent::DEVICE_ID_TOUCH_MOUSE); } TEST_CASE_TEMPLATE_APPLY(test_device, InputEventTypes); -TEST_CASE_TEMPLATE_DEFINE("[InputEvent] actions", T, test_actions) { - T event = T(); - InputMap inputMap = InputMap(); - - StringName testEventName("TestInputEvent"); - InputMap::get_singleton()->add_action(testEventName); - - SUBCASE("Action is present") { - CHECK(event.InputEvent::is_action(testEventName) == true); - CHECK(event.InputEvent::is_action(testEventName, true) == true); - } - - SUBCASE("Action has default pressed value") { - //default Action value is false - CHECK(event.is_action_pressed(testEventName) == false); - CHECK(event.is_action_pressed(testEventName, true) == false); - CHECK(event.is_action_pressed(testEventName, true, true) == false); - } - - SUBCASE("Action has default released value") { - //default Action value is true - CHECK(event.is_action_released(testEventName) == true); - CHECK(event.is_action_released(testEventName, true) == true); - } - - SUBCASE("Action has default strength value") { - //default Action value is 0.5f - CHECK(event.get_action_strength(testEventName) == 0.5f); - CHECK(event.get_action_strength(testEventName, true) == 0.5f); - } - - SUBCASE("Action has default strength value") { - //default Action value is 0.5f - CHECK(event.get_action_raw_strength(testEventName) == 0.5f); - CHECK(event.get_action_raw_strength(testEventName, true) == 0.5f); - } - - InputMap::get_singleton()->erase_action(testEventName); +TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Test action properties through InputEvent", T, test_actions) { + T event = T(); + InputMap inputMap = InputMap(); + + StringName testEventName("TestInputEvent"); + InputMap::get_singleton()->add_action(testEventName); + + SUBCASE("Action is present") { + CHECK(event.InputEvent::is_action(testEventName) == true); + CHECK(event.InputEvent::is_action(testEventName, true) == true); + } + + SUBCASE("Action has default pressed value") { + //default Action value is false + CHECK(event.InputEvent::is_action_pressed(testEventName) == false); + CHECK(event.InputEvent::is_action_pressed(testEventName, true) == false); + CHECK(event.InputEvent::is_action_pressed(testEventName, true, true) == false); + } + + SUBCASE("Action has default released value") { + //default Action value is true + CHECK(event.InputEvent::is_action_released(testEventName) == true); + CHECK(event.InputEvent::is_action_released(testEventName, true) == true); + } + + SUBCASE("Action has default strength value") { + //default Action value is 0.5f + CHECK(event.InputEvent::get_action_strength(testEventName) == 0.5f); + CHECK(event.InputEvent::get_action_strength(testEventName, true) == 0.5f); + } + + SUBCASE("Action has default strength value") { + //default Action value is 0.5f + CHECK(event.InputEvent::get_action_raw_strength(testEventName) == 0.5f); + CHECK(event.InputEvent::get_action_raw_strength(testEventName, true) == 0.5f); + } + + InputMap::get_singleton()->erase_action(testEventName); } TEST_CASE_TEMPLATE_APPLY(test_actions, InputEventTypes); From bd93afd8223306fd354d3424734c6e6916cbc8b6 Mon Sep 17 00:00:00 2001 From: Ian Gaither Date: Wed, 30 Nov 2022 20:03:34 -0800 Subject: [PATCH 3/4] Replaced std tuple with macro implementation, added class type to subcases --- tests/core/input/test_input_event.h | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/core/input/test_input_event.h b/tests/core/input/test_input_event.h index 5818ae42c7fc..8ba928229ae2 100644 --- a/tests/core/input/test_input_event.h +++ b/tests/core/input/test_input_event.h @@ -36,9 +36,24 @@ #include "tests/test_macros.h" +#define INPUT_EVENT_TYPES InputEventWithModifiers, \ + InputEventKey, \ + InputEventMouse, \ + InputEventMouseButton, \ + InputEventMouseMotion, \ + InputEventJoypadMotion, \ + InputEventJoypadButton, \ + InputEventScreenTouch, \ + InputEventScreenDrag, \ + InputEventAction, \ + InputEventGesture, \ + InputEventPanGesture, \ + InputEventMIDI, \ + InputEventShortcut + namespace TestInputEvent { -typedef std::tuple< +/*typedef std::tuple< InputEventWithModifiers, InputEventKey, InputEventMouse, @@ -53,7 +68,7 @@ typedef std::tuple< InputEventPanGesture, InputEventMIDI, InputEventShortcut - > InputEventTypes; + > InputEventTypes;*/ TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Event correctly changes and returns device", T, test_device) { T event = T(); @@ -66,7 +81,7 @@ TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Event correctly changes and returns devi CHECK(event.InputEvent::get_device() == InputEvent::DEVICE_ID_INTERNAL); CHECK(event.InputEvent::get_device() != InputEvent::DEVICE_ID_TOUCH_MOUSE); } -TEST_CASE_TEMPLATE_APPLY(test_device, InputEventTypes); +TEST_CASE_TEMPLATE_INVOKE(test_device, INPUT_EVENT_TYPES); TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Test action properties through InputEvent", T, test_actions) { T event = T(); @@ -75,31 +90,31 @@ TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Test action properties through InputEven StringName testEventName("TestInputEvent"); InputMap::get_singleton()->add_action(testEventName); - SUBCASE("Action is present") { + SUBCASE("[InputEvent] Action is present") { CHECK(event.InputEvent::is_action(testEventName) == true); CHECK(event.InputEvent::is_action(testEventName, true) == true); } - SUBCASE("Action has default pressed value") { + SUBCASE("[InputEvent] Action has default pressed value") { //default Action value is false CHECK(event.InputEvent::is_action_pressed(testEventName) == false); CHECK(event.InputEvent::is_action_pressed(testEventName, true) == false); CHECK(event.InputEvent::is_action_pressed(testEventName, true, true) == false); } - SUBCASE("Action has default released value") { + SUBCASE("[InputEvent] Action has default released value") { //default Action value is true CHECK(event.InputEvent::is_action_released(testEventName) == true); CHECK(event.InputEvent::is_action_released(testEventName, true) == true); } - SUBCASE("Action has default strength value") { + SUBCASE("[InputEvent] Action has default strength value") { //default Action value is 0.5f CHECK(event.InputEvent::get_action_strength(testEventName) == 0.5f); CHECK(event.InputEvent::get_action_strength(testEventName, true) == 0.5f); } - SUBCASE("Action has default strength value") { + SUBCASE("[InputEvent] Action has default strength value") { //default Action value is 0.5f CHECK(event.InputEvent::get_action_raw_strength(testEventName) == 0.5f); CHECK(event.InputEvent::get_action_raw_strength(testEventName, true) == 0.5f); @@ -107,7 +122,7 @@ TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Test action properties through InputEven InputMap::get_singleton()->erase_action(testEventName); } -TEST_CASE_TEMPLATE_APPLY(test_actions, InputEventTypes); +TEST_CASE_TEMPLATE_INVOKE(test_actions, INPUT_EVENT_TYPES); } // namespace TestInputEvent From 18aef3ae7bcb4a468c6a1e8e94157dc9ac938459 Mon Sep 17 00:00:00 2001 From: Ian Gaither Date: Wed, 30 Nov 2022 22:20:54 -0800 Subject: [PATCH 4/4] Removed tuple comment, fixed spacing in macro Removed extra space fixed spacing on multiline macro removed tabs from spacing on multiline macro Update test_input_event.h --- tests/core/input/test_input_event.h | 43 +++++++++-------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/tests/core/input/test_input_event.h b/tests/core/input/test_input_event.h index 8ba928229ae2..8d5ef8bc272f 100644 --- a/tests/core/input/test_input_event.h +++ b/tests/core/input/test_input_event.h @@ -37,39 +37,22 @@ #include "tests/test_macros.h" #define INPUT_EVENT_TYPES InputEventWithModifiers, \ - InputEventKey, \ - InputEventMouse, \ - InputEventMouseButton, \ - InputEventMouseMotion, \ - InputEventJoypadMotion, \ - InputEventJoypadButton, \ - InputEventScreenTouch, \ - InputEventScreenDrag, \ - InputEventAction, \ - InputEventGesture, \ - InputEventPanGesture, \ - InputEventMIDI, \ - InputEventShortcut + InputEventKey, \ + InputEventMouse, \ + InputEventMouseButton, \ + InputEventMouseMotion, \ + InputEventJoypadMotion, \ + InputEventJoypadButton, \ + InputEventScreenTouch, \ + InputEventScreenDrag, \ + InputEventAction, \ + InputEventGesture, \ + InputEventPanGesture, \ + InputEventMIDI, \ + InputEventShortcut namespace TestInputEvent { -/*typedef std::tuple< - InputEventWithModifiers, - InputEventKey, - InputEventMouse, - InputEventMouseButton, - InputEventMouseMotion, - InputEventJoypadMotion, - InputEventJoypadButton, - InputEventScreenTouch, - InputEventScreenDrag, - InputEventAction, - InputEventGesture, - InputEventPanGesture, - InputEventMIDI, - InputEventShortcut - > InputEventTypes;*/ - TEST_CASE_TEMPLATE_DEFINE("[InputEvent] Event correctly changes and returns device", T, test_device) { T event = T();