summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-30 10:00:45 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-30 10:00:45 +0100
commit2d47c4c307a83f0491cc2e2cc1191a3e813c149f (patch)
tree195052d143d79f2d73ebec860d4a04ad694fc5ad /tests
parentd01ac9c73686fdf86f083f4d3ee1301bb54d855f (diff)
parent23827d4303c19531be241e088d7a1ca884775a3e (diff)
Merge pull request #72213 from ARez2/ARez2/master
Add Unit test for InputEventMouse
Diffstat (limited to 'tests')
-rw-r--r--tests/core/input/test_input_event_mouse.h81
-rw-r--r--tests/test_main.cpp1
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/core/input/test_input_event_mouse.h b/tests/core/input/test_input_event_mouse.h
new file mode 100644
index 0000000000..0da4f14160
--- /dev/null
+++ b/tests/core/input/test_input_event_mouse.h
@@ -0,0 +1,81 @@
+/**************************************************************************/
+/* test_input_event_mouse.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* 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_MOUSE_H
+#define TEST_INPUT_EVENT_MOUSE_H
+
+#include "core/input/input_event.h"
+#include "tests/test_macros.h"
+
+namespace TestInputEventMouse {
+
+TEST_CASE("[InputEventMouse] Mouse button mask is set correctly") {
+ InputEventMouse mousekey;
+
+ mousekey.set_button_mask(MouseButtonMask::LEFT);
+ CHECK(mousekey.get_button_mask().has_flag(MouseButtonMask::LEFT));
+
+ mousekey.set_button_mask(MouseButtonMask::MB_XBUTTON1);
+ CHECK(mousekey.get_button_mask().has_flag(MouseButtonMask::MB_XBUTTON1));
+
+ mousekey.set_button_mask(MouseButtonMask::MB_XBUTTON2);
+ CHECK(mousekey.get_button_mask().has_flag(MouseButtonMask::MB_XBUTTON2));
+
+ mousekey.set_button_mask(MouseButtonMask::MIDDLE);
+ CHECK(mousekey.get_button_mask().has_flag(MouseButtonMask::MIDDLE));
+
+ mousekey.set_button_mask(MouseButtonMask::RIGHT);
+ CHECK(mousekey.get_button_mask().has_flag(MouseButtonMask::RIGHT));
+}
+
+TEST_CASE("[InputEventMouse] Setting the mouse position works correctly") {
+ InputEventMouse mousekey;
+
+ mousekey.set_position(Vector2{ 10, 10 });
+ CHECK(mousekey.get_position() == Vector2{ 10, 10 });
+
+ mousekey.set_position(Vector2{ -1, -1 });
+ CHECK(mousekey.get_position() == Vector2{ -1, -1 });
+}
+
+TEST_CASE("[InputEventMouse] Setting the global mouse position works correctly") {
+ InputEventMouse mousekey;
+
+ mousekey.set_global_position(Vector2{ 10, 10 });
+ CHECK(mousekey.get_global_position() == Vector2{ 10, 10 });
+ CHECK(mousekey.get_global_position() != Vector2{ 1, 1 });
+
+ mousekey.set_global_position(Vector2{ -1, -1 });
+ CHECK(mousekey.get_global_position() == Vector2{ -1, -1 });
+ CHECK(mousekey.get_global_position() != Vector2{ 1, 1 });
+}
+} // namespace TestInputEventMouse
+
+#endif // TEST_INPUT_EVENT_MOUSE_H
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 8c563f94ac..c7f2d4cbfb 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -32,6 +32,7 @@
#include "tests/core/config/test_project_settings.h"
#include "tests/core/input/test_input_event_key.h"
+#include "tests/core/input/test_input_event_mouse.h"
#include "tests/core/input/test_shortcut.h"
#include "tests/core/io/test_config_file.h"
#include "tests/core/io/test_file_access.h"