[libsigcplusplus/libsigc++-2-10] test_mem_fun: Test auto-disconnection with trackable.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/libsigc++-2-10] test_mem_fun: Test auto-disconnection with trackable.
- Date: Fri, 1 Apr 2016 10:02:16 +0000 (UTC)
commit de51a87156a14c65fbd436b0c3ea0508fe9332e1
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Apr 1 11:40:27 2016 +0200
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.
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]