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