]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - tests/test_ptr_fun.cc
Adjust the name of the library to match upstream
[ext/sigc++-2.0.git] / tests / test_ptr_fun.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 <sstream>
8 #include <sigc++/sigc++.h>
9 #include <cstdlib>
10
11 //TODO: put something like #ifndef FORTE ... #else ... #endif around:
12 #define ENABLE_TEST_OF_OVERLOADED_FUNCTIONS 0
13
14 namespace
15 {
16 std::ostringstream result_stream;
17
18 int foo()
19 {
20   result_stream << "foo()";
21   return 1;
22 }
23
24 void foo(int i1)
25 {
26   result_stream << "foo(int " << i1 << ")";
27 }
28
29 #if ENABLE_TEST_OF_OVERLOADED_FUNCTIONS
30 void bar(char i1)
31 {
32   result_stream << "bar(char " << (int)i1 << ")";
33 }
34 #endif
35
36 void bar(float i1)
37 {
38   result_stream << "bar(float " << i1 << ")";
39 }
40
41 double bar(int i1, int i2)
42 {
43   result_stream << "bar(int " << i1 << ", int " << i2 << ")";
44   return 1.0f;
45 }
46
47 struct test
48 {
49   static void foo()
50   {
51     result_stream << "test::foo()";
52   }
53 };
54
55 } // end anonymous namespace
56
57 int main(int argc, char* argv[])
58 {
59   auto util = TestUtilities::get_instance();
60
61   if (!util->check_command_args(argc, argv))
62     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
63
64   sigc::ptr_fun0(&foo)();
65   util->check_result(result_stream, "foo()");
66
67   sigc::ptr_fun1(&foo)(1);
68   util->check_result(result_stream, "foo(int 1)");
69
70 #if ENABLE_TEST_OF_OVERLOADED_FUNCTIONS
71   sigc::ptr_fun1<char>(&bar)(2);
72   util->check_result(result_stream, "bar(char 2)");
73
74   sigc::ptr_fun1<float>(&bar)(2.0f);
75   util->check_result(result_stream, "bar(float 2)");
76 #else
77   sigc::ptr_fun1(&bar)(2.0f);
78   util->check_result(result_stream, "bar(float 2)");
79 #endif
80
81   sigc::ptr_fun2(&bar)(3, 5);
82   util->check_result(result_stream, "bar(int 3, int 5)");
83
84   sigc::ptr_fun(&test::foo)();
85   util->check_result(result_stream, "test::foo()");
86
87   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
88 }