[libsigc++2] Add test_trackable_move.



commit 263fd4c1a53fae104622bbcfd2588f2a49604ad6
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Sep 1 16:10:27 2015 +0200

    Add test_trackable_move.
    
    It doesn't segfault, but I'm not sure it's doing what it should.
    See the TODO.

 tests/Makefile.am            |    2 ++
 tests/test_trackable_move.cc |   35 +++++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6c17d75..1167e83 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -46,6 +46,7 @@ check_PROGRAMS = \
   test_slot \
   test_slot_disconnect \
   test_trackable \
+  test_trackable_move \
   test_track_obj \
   test_visit_each
 
@@ -79,5 +80,6 @@ test_size_SOURCES            = test_size.cc $(sigc_test_util)
 test_slot_SOURCES            = test_slot.cc $(sigc_test_util)
 test_slot_disconnect_SOURCES = test_slot_disconnect.cc $(sigc_test_util)
 test_trackable_SOURCES       = test_trackable.cc $(sigc_test_util)
+test_trackable_move_SOURCES  = test_trackable_move.cc $(sigc_test_util)
 test_track_obj_SOURCES       = test_track_obj.cc $(sigc_test_util)
 test_visit_each_SOURCES      = test_visit_each.cc $(sigc_test_util)
diff --git a/tests/test_trackable_move.cc b/tests/test_trackable_move.cc
index 41d7aa4..b959647 100644
--- a/tests/test_trackable_move.cc
+++ b/tests/test_trackable_move.cc
@@ -18,27 +18,34 @@ class my_class: public sigc::trackable
 {
 public:
 
-  my_class(const myclass& src) = delete;
-  my_class& operator=(const myclass& src) = delete;
+  my_class()
+  : i(0)
+  {}
 
-  my_class(myclass&& src)
+  my_class(const my_class& src) = delete;
+  my_class& operator=(const my_class& src) = delete;
+
+  my_class(my_class&& src)
   : sigc::trackable(std::move(src)),
-    i(std::move(src.i);
+    i(std::move(src.i))
   {
+    src.i = 0;
   }
 
-  my_class& operator=(myclass&& src)
+  my_class& operator=(my_class&& src)
   {
     sigc::trackable::operator=(std::move(src));
     i = std::move(src.i);
+    src.i = 0;
+    return *this;
   }
 
-  int i;
-
   void foo()
   {
     result_stream << i;
   }
+
+  int i;
 };
 
 } // end anonymous namespace
@@ -57,10 +64,18 @@ int main(int argc, char* argv[])
     sl = sigc::mem_fun0(&t, &my_class::foo);
     sl();
     util->check_result(result_stream, "10");
-  }
 
-  sl();
-  util->check_result(result_stream, "");
+    //Create another trackable via a move:
+    my_class t2(std::move(t));
+    t2.i = 15;
+    result_stream.clear();
+
+    //TODO: Should this work without this line?
+    sl = sigc::mem_fun0(&t2, &my_class::foo);
+
+    sl();
+    util->check_result(result_stream, "15");
+  }
 
   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]