Skip to content

Commit 9526ba2

Browse files
committed
Add test_bind_as_slot.
This tests sigc::bind()'s indirect use of adaptor_functor<>. I added this because this doesn't work yet in the variadic_bind branch.
1 parent 611b26a commit 9526ba2

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

tests/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ check_PROGRAMS = \
2323
test_accum_iter \
2424
test_accumulated \
2525
test_bind \
26+
test_bind_as_slot \
2627
test_bind_ref \
2728
test_bind_refptr \
2829
test_bind_return \
@@ -59,6 +60,7 @@ sigc_test_util = testutilities.h testutilities.cc
5960
test_accum_iter_SOURCES = test_accum_iter.cc $(sigc_test_util)
6061
test_accumulated_SOURCES = test_accumulated.cc $(sigc_test_util)
6162
test_bind_SOURCES = test_bind.cc $(sigc_test_util)
63+
test_bind_as_slot_SOURCES = test_bind_as_slot.cc $(sigc_test_util)
6264
test_bind_ref_SOURCES = test_bind_ref.cc $(sigc_test_util)
6365
test_bind_refptr_SOURCES = test_bind_refptr.cc $(sigc_test_util)
6466
test_bind_return_SOURCES = test_bind_return.cc $(sigc_test_util)

tests/test_bind_as_slot.cc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)