diff options
-rw-r--r-- | tests/test_mem_fun.cc | 30 |
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; } |