[libsigcplusplus] test_signal(): Restructure this.



commit b0a3b087ed11d54cabe7f896213015919399393b
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Mar 11 10:36:41 2016 +0100

    test_signal(): Restructure this.
    
    To make it clearer and to keep the small tests more self-contained and
    separate.

 tests/test_signal.cc |   53 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 39 insertions(+), 14 deletions(-)
---
diff --git a/tests/test_signal.cc b/tests/test_signal.cc
index 1235a29..3157dd3 100644
--- a/tests/test_signal.cc
+++ b/tests/test_signal.cc
@@ -13,6 +13,8 @@
 
 namespace
 {
+
+TestUtilities* util = nullptr;
 std::ostringstream result_stream;
 
 int foo(int i)
@@ -21,12 +23,6 @@ int foo(int i)
   return 1;
 }
 
-int bar(float i)
-{
-  result_stream << "bar(float " << i << ") ";
-  return 1;
-}
-
 struct A : public sigc::trackable
 {
   int foo(int i)
@@ -42,21 +38,26 @@ struct A : public sigc::trackable
   }
 };
 
-} // end anonymous namespace
-
-int main(int argc, char* argv[])
+void test_empty_signal()
 {
-  auto util = TestUtilities::get_instance();
-
-  if (!util->check_command_args(argc, argv))
-    return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
-
   // signal
   sigc::signal<int,int> sig;
 
   // emit empty signal
   sig(0);
   util->check_result(result_stream, "");
+}
+
+int bar(float i)
+{
+  result_stream << "bar(float " << i << ") ";
+  return 1;
+}
+
+void test_auto_disconnection()
+{
+  // signal
+  sigc::signal<int,int> sig;
 
   // connect some slots before emitting & test auto-disconnection
   {
@@ -73,7 +74,10 @@ int main(int argc, char* argv[])
   sig(2);
   result_stream << sig.size();
   util->check_result(result_stream, "foo(int 2) bar(float 2) 2");
+}
 
+void test_reference()
+{
   // test reference
   A a;
   std::string str("guest book");
@@ -82,13 +86,34 @@ int main(int argc, char* argv[])
   sigstr(str);
   result_stream << str;
   util->check_result(result_stream, "A::foo(string 'guest book') foo was here");
+}
 
+void test_make_slot()
+{
   // test make_slot()
+  sigc::signal<int,int> sig;
+  sig.connect(sigc::ptr_fun(&foo));
+  sig.connect(sigc::ptr_fun(&bar));
   sig.connect(sigc::ptr_fun(&foo));
   sigc::signal<int,int> sig2;
   sig2.connect(sig.make_slot());
   sig2(3);
   util->check_result(result_stream, "foo(int 3) bar(float 3) foo(int 3) ");
+}
+
+} // end anonymous namespace
+
+int main(int argc, char* argv[])
+{
+  util = TestUtilities::get_instance();
+
+  if (!util->check_command_args(argc, argv))
+    return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
+
+  test_empty_signal();
+  test_auto_disconnection();
+  test_reference();
+  test_make_slot();
 
   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]