diff options
author | Markus Sauermann <6299227+Sauermann@users.noreply.github.com> | 2023-06-24 03:07:22 +0200 |
---|---|---|
committer | Markus Sauermann <6299227+Sauermann@users.noreply.github.com> | 2023-08-30 00:15:55 +0200 |
commit | c4705a590b5eb01d63afb907d6dad5c49d8f6fe1 (patch) | |
tree | 90dcb549205ed9c0d83ec77c3ab7b0cd473bb762 /tests | |
parent | 247c3548d810136ffe9c1694cd76db3236efaa90 (diff) | |
download | redot-engine-c4705a590b5eb01d63afb907d6dad5c49d8f6fe1.tar.gz |
Fix Object::notification order
Previously the `p_reversed` parameter didn't influence the order
in a correct way.
Also script overridden _notification functions were not called in
the correct order.
To fix this some `notification` functions had to add a `p_reversed`
parameter.
This made it necessary to adjust cpp-bindings.
Co-authored-by: David Snopek <dsnopek@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/object/test_object.h | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h index a3d6b38ca4..e5d91db650 100644 --- a/tests/core/object/test_object.h +++ b/tests/core/object/test_object.h @@ -98,7 +98,7 @@ public: Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override { return Variant(); } - void notification(int p_notification) override { + void notification(int p_notification, bool p_reversed = false) override { } Ref<Script> get_script() const override { return Ref<Script>(); @@ -426,6 +426,74 @@ TEST_CASE("[Object] Signals") { } } +class NotificationObject1 : public Object { + GDCLASS(NotificationObject1, Object); + +protected: + void _notification(int p_what) { + switch (p_what) { + case 12345: { + order_internal1 = order_global++; + } break; + } + } + +public: + static int order_global; + int order_internal1 = -1; + + void reset_order() { + order_internal1 = -1; + order_global = 1; + } +}; + +int NotificationObject1::order_global = 1; + +class NotificationObject2 : public NotificationObject1 { + GDCLASS(NotificationObject2, NotificationObject1); + +protected: + void _notification(int p_what) { + switch (p_what) { + case 12345: { + order_internal2 = order_global++; + } break; + } + } + +public: + int order_internal2 = -1; + void reset_order() { + NotificationObject1::reset_order(); + order_internal2 = -1; + } +}; + +TEST_CASE("[Object] Notification order") { // GH-52325 + NotificationObject2 *test_notification_object = memnew(NotificationObject2); + + SUBCASE("regular order") { + test_notification_object->notification(12345, false); + + CHECK_EQ(test_notification_object->order_internal1, 1); + CHECK_EQ(test_notification_object->order_internal2, 2); + + test_notification_object->reset_order(); + } + + SUBCASE("reverse order") { + test_notification_object->notification(12345, true); + + CHECK_EQ(test_notification_object->order_internal1, 2); + CHECK_EQ(test_notification_object->order_internal2, 1); + + test_notification_object->reset_order(); + } + + memdelete(test_notification_object); +} + } // namespace TestObject #endif // TEST_OBJECT_H |