diff options
author | Murray Cumming <murrayc@murrayc.com> | 2016-03-01 16:12:50 +0100 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2016-03-01 16:21:04 +0100 |
commit | 2be3b6e83fc9d086800bf51d155d16a10ee43346 (patch) | |
tree | ef7dc93357074d47ca3011a51b11714c92e6552f | |
parent | 8997797fdae6bd2f0fa46c6661b9e08f5579cfb2 (diff) | |
download | sigc++-variadic_bind.tar.gz |
Add test_bind_as_slot.variadic_bind
This tests sigc::bind()'s indirect use of adaptor_functor<>.
I added this because this doesn't work yet in the variadic_bind branch.
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/test_bind_as_slot.cc | 71 |
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 206711a..09ae62e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,6 +23,7 @@ check_PROGRAMS = \ test_accum_iter \ test_accumulated \ test_bind \ + test_bind_as_slot \ test_bind_ref \ test_bind_refptr \ test_bind_return \ @@ -64,6 +65,7 @@ sigc_test_util = testutilities.h testutilities.cc test_accum_iter_SOURCES = test_accum_iter.cc $(sigc_test_util) test_accumulated_SOURCES = test_accumulated.cc $(sigc_test_util) test_bind_SOURCES = test_bind.cc $(sigc_test_util) +test_bind_as_slot_SOURCES = test_bind_as_slot.cc $(sigc_test_util) test_bind_ref_SOURCES = test_bind_ref.cc $(sigc_test_util) test_bind_refptr_SOURCES = test_bind_refptr.cc $(sigc_test_util) test_bind_return_SOURCES = test_bind_return.cc $(sigc_test_util) diff --git a/tests/test_bind_as_slot.cc b/tests/test_bind_as_slot.cc new file mode 100644 index 0000000..28bcf4f --- /dev/null +++ b/tests/test_bind_as_slot.cc @@ -0,0 +1,71 @@ +// -*- c++ -*- +/* Copyright 2002, The libsigc++ Development Team + * Assigned to public domain. Use as you wish without restriction. + */ + +#include "testutilities.h" +#include <sigc++/adaptors/bind.h> +#include <sigc++/functors/slot.h> +#include <sstream> +#include <string> +#include <functional> //For std::ref(). +#include <cstdlib> + +namespace +{ + +std::ostringstream result_stream; + +bool func_to_bind(int a, int b) +{ + result_stream << "func_to_bind(" << a << ", " << b << ")"; + return true; +} + +bool func_to_bind_with_iter(int a, std::string::iterator& b) +{ + result_stream << "func_to_bind_with_iter(" << a << ", " << *b << ")"; + return true; +} + +bool func_to_bind_with_const_iter(int a, std::string::const_iterator& b) +{ + result_stream << "func_to_bind_with_const_iter(" << a << ", " << *b << ")"; + return true; +} + +} // end anonymous namespace + +int main(int argc, char* argv[]) +{ + auto util = TestUtilities::get_instance(); + + if (!util->check_command_args(argc, argv)) + return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE; + + + //Test that sigc::bind()'s result can be converted to a sigc::slot<>. + { + sigc::slot<bool, int> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind), 2); + bound_slot(1); + util->check_result(result_stream, "func_to_bind(1, 2)"); + } + + //Test with a non-const iterator: + { + std::string c = "2"; + sigc::slot<bool, int> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind_with_iter), c.begin()); + bound_slot(1); + util->check_result(result_stream, "func_to_bind_with_iter(1, 2)"); + } + + //Test with a const_iterator: + { + const std::string c = "2"; + sigc::slot<bool, int> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind_with_const_iter), c.begin()); + bound_slot(1); + util->check_result(result_stream, "func_to_bind_with_const_iter(1, 2)"); + } + + return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE; +} |