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.h134
1 files changed, 83 insertions, 51 deletions
diff --git a/tests/test_macros.h b/tests/test_macros.h
index b04c2117b7..eff09fb4b0 100644
--- a/tests/test_macros.h
+++ b/tests/test_macros.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -63,22 +63,22 @@
// Stringify all `Variant` compatible types for doctest output by default.
// https://github.com/onqtam/doctest/blob/master/doc/markdown/stringification.md
-#define DOCTEST_STRINGIFY_VARIANT(m_type) \
- template <> \
- struct doctest::StringMaker<m_type> { \
- static doctest::String convert(const m_type &p_val) { \
- const Variant val = p_val; \
- return val.get_construct_string().utf8().get_data(); \
- } \
+#define DOCTEST_STRINGIFY_VARIANT(m_type) \
+ template <> \
+ struct doctest::StringMaker<m_type> { \
+ static doctest::String convert(const m_type &p_val) { \
+ const Variant val = p_val; \
+ return val.operator ::String().utf8().get_data(); \
+ } \
};
-#define DOCTEST_STRINGIFY_VARIANT_POINTER(m_type) \
- template <> \
- struct doctest::StringMaker<m_type> { \
- static doctest::String convert(const m_type *p_val) { \
- const Variant val = p_val; \
- return val.get_construct_string().utf8().get_data(); \
- } \
+#define DOCTEST_STRINGIFY_VARIANT_POINTER(m_type) \
+ template <> \
+ struct doctest::StringMaker<m_type> { \
+ static doctest::String convert(const m_type *p_val) { \
+ const Variant val = p_val; \
+ return val.operator ::String().utf8().get_data(); \
+ } \
};
DOCTEST_STRINGIFY_VARIANT(Variant);
@@ -122,20 +122,21 @@ DOCTEST_STRINGIFY_VARIANT(PackedColorArray);
// Example usage: `godot --test gdscript-parser`.
typedef void (*TestFunc)();
-extern Map<String, TestFunc> *test_commands;
+extern HashMap<String, TestFunc> *test_commands;
int register_test_command(String p_command, TestFunc p_function);
-#define REGISTER_TEST_COMMAND(m_command, m_function) \
- DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \
- register_test_command(m_command, m_function); \
- DOCTEST_GLOBAL_NO_WARNINGS_END()
+#define REGISTER_TEST_COMMAND(m_command, m_function) \
+ DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), \
+ register_test_command(m_command, m_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::CMD).
-// SEND_GUI_MOUSE_EVENT - takes an object, position, mouse button and mouse mask e.g SEND_GUI_MOUSE_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE);
-// SEND_GUI_DOUBLE_CLICK - takes an object and a postion. e.g SEND_GUI_DOUBLE_CLICK(code_edit, Vector2(50, 50));
+// 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), MouseButton::MASK_LEFT, KeyModifierMask::CMD);
+// SEND_GUI_DOUBLE_CLICK - takes an object, position and modifiers. e.g SEND_GUI_DOUBLE_CLICK(code_edit, Vector2(50, 50), KeyModifierMask::CMD);
#define SEND_GUI_ACTION(m_object, m_action) \
{ \
@@ -143,7 +144,7 @@ int register_test_command(String p_command, TestFunc p_function);
const List<Ref<InputEvent>>::Element *first_event = events->front(); \
Ref<InputEventKey> event = first_event->get(); \
event->set_pressed(true); \
- m_object->gui_input(event); \
+ m_object->get_viewport()->push_input(event); \
MessageQueue::get_singleton()->flush(); \
}
@@ -151,31 +152,64 @@ int register_test_command(String p_command, TestFunc p_function);
{ \
Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
event->set_pressed(true); \
- m_object->gui_input(event); \
+ m_object->get_viewport()->push_input(event); \
MessageQueue::get_singleton()->flush(); \
}
-#define _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask) \
- Ref<InputEventMouseButton> event; \
- event.instantiate(); \
- event->set_position(m_local_pos); \
- event->set_button_index(m_input); \
- event->set_button_mask(m_mask); \
+#define _UPDATE_EVENT_MODIFERS(m_event, m_modifers) \
+ m_event->set_shift_pressed(((m_modifers)&KeyModifierMask::SHIFT) != Key::NONE); \
+ m_event->set_alt_pressed(((m_modifers)&KeyModifierMask::ALT) != Key::NONE); \
+ m_event->set_ctrl_pressed(((m_modifers)&KeyModifierMask::CTRL) != Key::NONE); \
+ m_event->set_command_pressed(((m_modifers)&KeyModifierMask::CMD) != 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); \
event->set_pressed(true);
-#define SEND_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
+#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_DOUBLE_CLICK(m_object, m_local_pos) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, MouseButton::LEFT, MouseButton::LEFT); \
- event->set_double_click(true); \
- m_object->get_viewport()->push_input(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_DOUBLE_CLICK(m_object, m_local_pos, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, MouseButton::LEFT, MouseButton::LEFT, m_modifers); \
+ event->set_double_click(true); \
+ m_object->get_viewport()->push_input(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 = _print_error_enabled; \
+ _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(); \
+ _print_error_enabled = errors_enabled; \
}
// Utility class / macros for testing signals
@@ -192,14 +226,14 @@ int register_test_command(String p_command, TestFunc p_function);
//
// Use SIGNAL_DISCARD("signal_name") to discard records all of the given signal, use only in placed you don't need to check.
//
-// All signals are automaticaly discared between test/sub test cases.
+// All signals are automatically discarded between test/sub test cases.
class SignalWatcher : public Object {
private:
inline static SignalWatcher *singleton;
- /* Equal to: Map<String, Vector<Vector<Variant>>> */
- Map<String, Array> _signals;
+ /* Equal to: RBMap<String, Vector<Vector<Variant>>> */
+ HashMap<String, Array> _signals;
void _add_signal_entry(const Array &p_args, const String &p_name) {
if (!_signals.has(p_name)) {
_signals[p_name] = Array();
@@ -237,22 +271,20 @@ public:
static SignalWatcher *get_singleton() { return singleton; }
void watch_signal(Object *p_object, const String &p_signal) {
- Vector<Variant> args;
- args.push_back(p_signal);
MethodInfo method_info;
ClassDB::get_signal(p_object->get_class(), p_signal, &method_info);
switch (method_info.arguments.size()) {
case 0: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero).bind(p_signal));
} break;
case 1: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one).bind(p_signal));
} break;
case 2: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two).bind(p_signal));
} break;
case 3: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three).bind(p_signal));
} break;
default: {
MESSAGE("Signal ", p_signal, " arg count not supported.");