diff options
Diffstat (limited to 'tests/test_macros.h')
| -rw-r--r-- | tests/test_macros.h | 89 | 
1 files changed, 44 insertions, 45 deletions
diff --git a/tests/test_macros.h b/tests/test_macros.h index 80a93c8327..5d1bcdecf4 100644 --- a/tests/test_macros.h +++ b/tests/test_macros.h @@ -134,16 +134,16 @@ 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); +// 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_object, m_action)                                                           \ +#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();                          \ @@ -153,7 +153,7 @@ int register_test_command(String p_command, TestFunc p_function);  		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);                                            \ @@ -167,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) \ +#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_screen_pos, m_input, m_mask, m_modifers) \  	{                                                                                   \ -		_CREATE_GUI_MOUSE_EVENT(m_object, m_local_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_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);                                                               \ -		_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);                                                    \ -		_SEND_DISPLAYSERVER_EVENT(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);                             \ -		_SEND_DISPLAYSERVER_EVENT(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  |