summaryrefslogtreecommitdiff
path: root/tests/test_macros.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_macros.h')
-rw-r--r--tests/test_macros.h101
1 files changed, 52 insertions, 49 deletions
diff --git a/tests/test_macros.h b/tests/test_macros.h
index 3074c1abf5..5d1bcdecf4 100644
--- a/tests/test_macros.h
+++ b/tests/test_macros.h
@@ -31,6 +31,8 @@
#ifndef TEST_MACROS_H
#define TEST_MACROS_H
+#include "display_server_mock.h"
+
#include "core/core_globals.h"
#include "core/input/input_map.h"
#include "core/object/message_queue.h"
@@ -132,28 +134,30 @@ int register_test_command(String p_command, TestFunc p_function);
// Utility macros to send an event actions to a given object
// Requires Message Queue and InputMap to be setup.
-// SEND_GUI_ACTION - takes an object and a input map key. e.g SEND_GUI_ACTION(code_edit, "ui_text_newline").
-// SEND_GUI_KEY_EVENT - takes an object and a keycode set. e.g SEND_GUI_KEY_EVENT(code_edit, Key::A | KeyModifierMask::META).
-// SEND_GUI_MOUSE_BUTTON_EVENT - takes an object, position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
-// SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT - takes an object, position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
-// SEND_GUI_MOUSE_MOTION_EVENT - takes an object, position, mouse mask and modifiers e.g SEND_GUI_MOUSE_MOTION_EVENT(code_edit, Vector2(50, 50), MouseButtonMask::LEFT, KeyModifierMask::META);
-// SEND_GUI_DOUBLE_CLICK - takes an object, position and modifiers. e.g SEND_GUI_DOUBLE_CLICK(code_edit, Vector2(50, 50), KeyModifierMask::META);
-
-#define SEND_GUI_ACTION(m_object, m_action) \
+// SEND_GUI_ACTION - takes an input map key. e.g SEND_GUI_ACTION("ui_text_newline").
+// SEND_GUI_KEY_EVENT - takes a keycode set. e.g SEND_GUI_KEY_EVENT(Key::A | KeyModifierMask::META).
+// SEND_GUI_MOUSE_BUTTON_EVENT - takes a position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_EVENT(Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
+// SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT - takes a position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
+// SEND_GUI_MOUSE_MOTION_EVENT - takes a position, mouse mask and modifiers e.g SEND_GUI_MOUSE_MOTION_EVENT(Vector2(50, 50), MouseButtonMask::LEFT, KeyModifierMask::META);
+// SEND_GUI_DOUBLE_CLICK - takes a position and modifiers. e.g SEND_GUI_DOUBLE_CLICK(Vector2(50, 50), KeyModifierMask::META);
+
+#define _SEND_DISPLAYSERVER_EVENT(m_event) ((DisplayServerMock *)(DisplayServer::get_singleton()))->simulate_event(m_event);
+
+#define SEND_GUI_ACTION(m_action) \
{ \
const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(m_action); \
const List<Ref<InputEvent>>::Element *first_event = events->front(); \
Ref<InputEventKey> event = first_event->get(); \
event->set_pressed(true); \
- m_object->get_viewport()->push_input(event); \
+ _SEND_DISPLAYSERVER_EVENT(event); \
MessageQueue::get_singleton()->flush(); \
}
-#define SEND_GUI_KEY_EVENT(m_object, m_input) \
+#define SEND_GUI_KEY_EVENT(m_input) \
{ \
Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
event->set_pressed(true); \
- m_object->get_viewport()->push_input(event); \
+ _SEND_DISPLAYSERVER_EVENT(event); \
MessageQueue::get_singleton()->flush(); \
}
@@ -163,53 +167,52 @@ int register_test_command(String p_command, TestFunc p_function);
m_event->set_ctrl_pressed(((m_modifers)&KeyModifierMask::CTRL) != Key::NONE); \
m_event->set_meta_pressed(((m_modifers)&KeyModifierMask::META) != Key::NONE);
-#define _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers) \
- Ref<InputEventMouseButton> event; \
- event.instantiate(); \
- event->set_position(m_local_pos); \
- event->set_button_index(m_input); \
- event->set_button_mask(m_mask); \
- event->set_factor(1); \
- _UPDATE_EVENT_MODIFERS(event, m_modifers); \
+#define _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
+ Ref<InputEventMouseButton> event; \
+ event.instantiate(); \
+ event->set_position(m_screen_pos); \
+ event->set_button_index(m_input); \
+ event->set_button_mask(m_mask); \
+ event->set_factor(1); \
+ _UPDATE_EVENT_MODIFERS(event, m_modifers); \
event->set_pressed(true);
-#define SEND_GUI_MOUSE_BUTTON_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
+#define SEND_GUI_MOUSE_BUTTON_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers); \
+ _SEND_DISPLAYSERVER_EVENT(event); \
+ MessageQueue::get_singleton()->flush(); \
}
-#define SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers); \
- event->set_pressed(false); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
+#define SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers); \
+ event->set_pressed(false); \
+ _SEND_DISPLAYSERVER_EVENT(event); \
+ MessageQueue::get_singleton()->flush(); \
}
-#define SEND_GUI_DOUBLE_CLICK(m_object, m_local_pos, m_modifers) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, MouseButton::LEFT, 0, m_modifers); \
- event->set_double_click(true); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
+#define SEND_GUI_DOUBLE_CLICK(m_screen_pos, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_screen_pos, MouseButton::LEFT, 0, m_modifers); \
+ event->set_double_click(true); \
+ _SEND_DISPLAYSERVER_EVENT(event); \
+ MessageQueue::get_singleton()->flush(); \
}
// We toggle _print_error_enabled to prevent display server not supported warnings.
-#define SEND_GUI_MOUSE_MOTION_EVENT(m_object, m_local_pos, m_mask, m_modifers) \
- { \
- bool errors_enabled = CoreGlobals::print_error_enabled; \
- CoreGlobals::print_error_enabled = false; \
- Ref<InputEventMouseMotion> event; \
- event.instantiate(); \
- event->set_position(m_local_pos); \
- event->set_button_mask(m_mask); \
- event->set_relative(Vector2(10, 10)); \
- _UPDATE_EVENT_MODIFERS(event, m_modifers); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
- CoreGlobals::print_error_enabled = errors_enabled; \
+#define SEND_GUI_MOUSE_MOTION_EVENT(m_screen_pos, m_mask, m_modifers) \
+ { \
+ bool errors_enabled = CoreGlobals::print_error_enabled; \
+ CoreGlobals::print_error_enabled = false; \
+ Ref<InputEventMouseMotion> event; \
+ event.instantiate(); \
+ event->set_position(m_screen_pos); \
+ event->set_button_mask(m_mask); \
+ _UPDATE_EVENT_MODIFERS(event, m_modifers); \
+ _SEND_DISPLAYSERVER_EVENT(event); \
+ MessageQueue::get_singleton()->flush(); \
+ CoreGlobals::print_error_enabled = errors_enabled; \
}
// Utility class / macros for testing signals