summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-04-01 11:40:27 +0200
committerMurray Cumming <murrayc@murrayc.com>2016-04-01 12:03:43 +0200
commit7f4d42206f41c638e60b7a4db338d05ef01d7502 (patch)
treebd4052a2ceb4b94db391bed3875c6aa527801996 /tests
parentcba1d904afe85ea24d39608c0469592876ef68be (diff)
downloadsigc++-7f4d42206f41c638e60b7a4db338d05ef01d7502.tar.gz
test_mem_fun: Test auto-disconnection with trackable.
This is probably tested somewhere else already, but I like having it here too because it is an important reason for slot<> to exist, compared to a simple std::function.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_mem_fun.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_mem_fun.cc b/tests/test_mem_fun.cc
index 1b32ae6..403abba 100644
--- a/tests/test_mem_fun.cc
+++ b/tests/test_mem_fun.cc
@@ -142,6 +142,34 @@ void test_bound()
#endif
}
+class TestAutoDisconnect : public sigc::trackable
+{
+public:
+ void foo()
+ {
+ result_stream << "TestAutoDisconnect::foo() called.";
+ }
+};
+
+void test_auto_disconnect()
+{
+ //Check that slot doesn't try to call a method on a destroyed instance,
+ //when the instance's class derives from trackable.
+ sigc::slot<void()> slot_of_member_method;
+ {
+ TestAutoDisconnect t;
+ slot_of_member_method = sigc::mem_fun(t, &TestAutoDisconnect::foo);
+
+ //The method should be called:
+ slot_of_member_method();
+ util->check_result(result_stream, "TestAutoDisconnect::foo() called.");
+ }
+
+ //The method should not be called:
+ slot_of_member_method();
+ util->check_result(result_stream, "");
+}
+
int
main(int argc, char* argv[])
{
@@ -163,5 +191,7 @@ main(int argc, char* argv[])
test_bound();
+ test_auto_disconnect();
+
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}