]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - tests/test_retype.cc
Adjust the name of the library to match upstream
[ext/sigc++-2.0.git] / tests / test_retype.cc
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/retype.h>
8 #include <sstream>
9 #include <cstdlib>
10
11 namespace
12 {
13
14 TestUtilities* util = nullptr;
15 std::ostringstream result_stream;
16
17 struct foo : public sigc::trackable
18 {
19   float test_int(int i)
20   {
21     result_stream << "foo::test_int(int " << i << ") ";
22     return i * 1.5f;
23   }
24
25   float test_float(float f)
26   {
27     result_stream << "foo::test_float(float " << f << ") ";
28     return f * 5;
29   }
30 };
31
32 void bar(short s)
33 {
34   result_stream << "bar(short " << s << ")";
35 }
36
37 void test_member_int()
38 {
39   foo foo_;
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");
42 }
43
44 void test_member_float()
45 {
46   foo foo_;
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");
49 }
50
51 void test_ptr_fun()
52 {
53   sigc::retype(sigc::ptr_fun(&bar))(6.789f);
54   util->check_result(result_stream, "bar(short 6)");
55 }
56
57 void test_member_int_with_slot()
58 {
59   foo foo_;
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");
63 }
64
65 void test_member_float_with_slot()
66 {
67   foo foo_;
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");
71 }
72
73 void test_ptr_fun_with_slot()
74 {
75   sigc::slot<void,double> s3 = sigc::retype(sigc::ptr_fun(&bar));
76   s3(6.789);
77   util->check_result(result_stream, "bar(short 6)");
78 }
79
80 void test_retype_slot()
81 {
82   foo foo_;
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");
87 }
88
89 void test_std_function_style_syntax()
90 {
91   foo foo_;
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");
95 }
96
97 } // end anonymous namespace
98
99 int main(int argc, char* argv[])
100 {
101   util = TestUtilities::get_instance();
102
103   if (!util->check_command_args(argc, argv))
104     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
105
106   test_member_int();
107   test_member_float();
108   test_ptr_fun();
109
110   test_member_int_with_slot();
111   test_member_float_with_slot();
112   test_ptr_fun_with_slot();
113
114   test_retype_slot();
115
116   test_std_function_style_syntax();
117
118   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
119 }