summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarius Hanl <mariushanl@web.de>2022-12-27 01:27:43 +0100
committerMarius Hanl <mariushanl@web.de>2022-12-29 16:07:45 +0100
commitb9be3ce75e87a814fa8b9df0a999e6a3ef43ad1e (patch)
tree2e191f2d54ec5b692134b1b076ecebd210c86c40 /tests
parentb6e06038f8a373f7fb8d26e92d5f06887e459598 (diff)
Add tests for signals
- Adding signals - Emitting signals
Diffstat (limited to 'tests')
-rw-r--r--tests/core/object/test_object.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h
index f5c5de7fdf..5feb3a4054 100644
--- a/tests/core/object/test_object.h
+++ b/tests/core/object/test_object.h
@@ -281,6 +281,84 @@ TEST_CASE("[Object] Absent name getter") {
actual_value == Variant(),
"The returned value should equal nil variant.");
}
+
+TEST_CASE("[Object] Signals") {
+ Object object;
+
+ CHECK_FALSE(object.has_signal("my_custom_signal"));
+
+ List<MethodInfo> signals_before;
+ object.get_signal_list(&signals_before);
+
+ object.add_user_signal(MethodInfo("my_custom_signal"));
+
+ CHECK(object.has_signal("my_custom_signal"));
+
+ List<MethodInfo> signals_after;
+ object.get_signal_list(&signals_after);
+
+ // Should be one more signal.
+ CHECK_EQ(signals_before.size() + 1, signals_after.size());
+
+ SUBCASE("Adding the same user signal again should not have any effect") {
+ CHECK(object.has_signal("my_custom_signal"));
+ ERR_PRINT_OFF;
+ object.add_user_signal(MethodInfo("my_custom_signal"));
+ ERR_PRINT_ON;
+ CHECK(object.has_signal("my_custom_signal"));
+
+ List<MethodInfo> signals_after_existing_added;
+ object.get_signal_list(&signals_after_existing_added);
+
+ CHECK_EQ(signals_after.size(), signals_after_existing_added.size());
+ }
+
+ SUBCASE("Trying to add a preexisting signal should not have any effect") {
+ CHECK(object.has_signal("script_changed"));
+ ERR_PRINT_OFF;
+ object.add_user_signal(MethodInfo("script_changed"));
+ ERR_PRINT_ON;
+ CHECK(object.has_signal("script_changed"));
+
+ List<MethodInfo> signals_after_existing_added;
+ object.get_signal_list(&signals_after_existing_added);
+
+ CHECK_EQ(signals_after.size(), signals_after_existing_added.size());
+ }
+
+ SUBCASE("Adding an empty signal should not have any effect") {
+ CHECK_FALSE(object.has_signal(""));
+ ERR_PRINT_OFF;
+ object.add_user_signal(MethodInfo(""));
+ ERR_PRINT_ON;
+ CHECK_FALSE(object.has_signal(""));
+
+ List<MethodInfo> signals_after_empty_added;
+ object.get_signal_list(&signals_after_empty_added);
+
+ CHECK_EQ(signals_after.size(), signals_after_empty_added.size());
+ }
+
+ SUBCASE("Emitting a non existing signal will return an error") {
+ Error err = object.emit_signal("some_signal");
+ CHECK(err == ERR_UNAVAILABLE);
+ }
+
+ SUBCASE("Emitting an existing signal should call the connected method") {
+ Array empty_signal_args;
+ empty_signal_args.push_back(Array());
+
+ SIGNAL_WATCH(&object, "my_custom_signal");
+ SIGNAL_CHECK_FALSE("my_custom_signal");
+
+ Error err = object.emit_signal("my_custom_signal");
+ CHECK(err == OK);
+
+ SIGNAL_CHECK("my_custom_signal", empty_signal_args);
+ SIGNAL_UNWATCH(&object, "my_custom_signal");
+ }
+}
+
} // namespace TestObject
#endif // TEST_OBJECT_H