"Fossies" - the Fresh Open Source Software Archive

Member "libsigc++-2.99.13/tests/test_bind_as_slot.cc" (4 May 2019, 1829 Bytes) of package /linux/misc/libsigc++-2.99.13.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright 2002 - 2016, The libsigc++ Development Team
    2  *  Assigned to public domain.  Use as you wish without restriction.
    3  */
    4 
    5 #include "testutilities.h"
    6 #include <sigc++/adaptors/bind.h>
    7 #include <sigc++/functors/slot.h>
    8 
    9 namespace
   10 {
   11 
   12 std::ostringstream result_stream;
   13 
   14 bool
   15 func_to_bind(int a, int b)
   16 {
   17   result_stream << "func_to_bind(" << a << ", " << b << ")";
   18   return true;
   19 }
   20 
   21 bool
   22 func_to_bind_with_iter(int a, std::string::iterator& b)
   23 {
   24   result_stream << "func_to_bind_with_iter(" << a << ", " << *b << ")";
   25   return true;
   26 }
   27 
   28 bool
   29 func_to_bind_with_const_iter(int a, std::string::const_iterator& b)
   30 {
   31   result_stream << "func_to_bind_with_const_iter(" << a << ", " << *b << ")";
   32   return true;
   33 }
   34 
   35 } // end anonymous namespace
   36 
   37 int
   38 main(int argc, char* argv[])
   39 {
   40   auto util = TestUtilities::get_instance();
   41 
   42   if (!util->check_command_args(argc, argv))
   43     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
   44 
   45   // Test that sigc::bind()'s result can be converted to a sigc::slot<>.
   46   {
   47     sigc::slot<bool(int)> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind), 2);
   48     bound_slot(1);
   49     util->check_result(result_stream, "func_to_bind(1, 2)");
   50   }
   51 
   52   // Test with a non-const iterator:
   53   {
   54     std::string c = "2";
   55     sigc::slot<bool(int)> bound_slot =
   56       sigc::bind(sigc::ptr_fun(&func_to_bind_with_iter), c.begin());
   57     bound_slot(1);
   58     util->check_result(result_stream, "func_to_bind_with_iter(1, 2)");
   59   }
   60 
   61   // Test with a const_iterator:
   62   {
   63     const std::string c = "2";
   64     sigc::slot<bool(int)> bound_slot =
   65       sigc::bind(sigc::ptr_fun(&func_to_bind_with_const_iter), c.begin());
   66     bound_slot(1);
   67     util->check_result(result_stream, "func_to_bind_with_const_iter(1, 2)");
   68   }
   69 
   70   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
   71 }