summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-08-30 08:44:36 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-08-30 08:44:36 +0200
commit8edc0b43b94bcc04defeeebd7ce120a0131ff511 (patch)
treebfa167f5598efc3f8c0a05b131be6bb8812b7edd /tests
parentd2f76e87869b892d7992696e0b381c5afebe3d0d (diff)
parentc4705a590b5eb01d63afb907d6dad5c49d8f6fe1 (diff)
downloadredot-engine-8edc0b43b94bcc04defeeebd7ce120a0131ff511.tar.gz
Merge pull request #78634 from Sauermann/fix-notification-order
Fix `Object::notification` order
Diffstat (limited to 'tests')
-rw-r--r--tests/core/object/test_object.h70
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