2 /* Copyright 2002, The libsigc++ Development Team
3 * Assigned to public domain. Use as you wish without restriction.
6 #include "testutilities.h"
7 #include <sigc++/adaptors/retype.h>
14 TestUtilities* util = nullptr;
15 std::ostringstream result_stream;
17 struct foo : public sigc::trackable
21 result_stream << "foo::test_int(int " << i << ") ";
25 float test_float(float f)
27 result_stream << "foo::test_float(float " << f << ") ";
34 result_stream << "bar(short " << s << ")";
37 void test_member_int()
40 result_stream << sigc::retype(sigc::mem_fun(foo_, &foo::test_int))(1.234f);
41 util->check_result(result_stream, "foo::test_int(int 1) 1.5");
44 void test_member_float()
47 result_stream << sigc::retype(sigc::mem_fun(foo_, &foo::test_float))(5);
48 util->check_result(result_stream, "foo::test_float(float 5) 25");
53 sigc::retype(sigc::ptr_fun(&bar))(6.789f);
54 util->check_result(result_stream, "bar(short 6)");
57 void test_member_int_with_slot()
60 sigc::slot<float,float> s1 = sigc::retype(sigc::mem_fun(foo_, &foo::test_int));
61 result_stream << s1(1.234f);
62 util->check_result(result_stream, "foo::test_int(int 1) 1.5");
65 void test_member_float_with_slot()
68 sigc::slot<float,int> s2 = sigc::retype(sigc::mem_fun(foo_, &foo::test_float));
69 result_stream << s2(5);
70 util->check_result(result_stream, "foo::test_float(float 5) 25");
73 void test_ptr_fun_with_slot()
75 sigc::slot<void,double> s3 = sigc::retype(sigc::ptr_fun(&bar));
77 util->check_result(result_stream, "bar(short 6)");
80 void test_retype_slot()
83 sigc::slot<float,float> s1 = sigc::retype(sigc::mem_fun(foo_, &foo::test_int));
84 sigc::slot<float,int> s2 = sigc::retype(s1);
85 result_stream << s2(5);
86 util->check_result(result_stream, "foo::test_int(int 5) 7.5");
89 void test_std_function_style_syntax()
92 sigc::slot<float(float)> s1 = sigc::retype(sigc::mem_fun(foo_, &foo::test_int));
93 result_stream << s1(1.234f);
94 util->check_result(result_stream, "foo::test_int(int 1) 1.5");
97 } // end anonymous namespace
99 int main(int argc, char* argv[])
101 util = TestUtilities::get_instance();
103 if (!util->check_command_args(argc, argv))
104 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
110 test_member_int_with_slot();
111 test_member_float_with_slot();
112 test_ptr_fun_with_slot();
116 test_std_function_style_syntax();
118 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;