Imported Upstream version 2.99.2
[platform/upstream/libsigc++.git] / tests / test_limit_reference.cc
1 #include "testutilities.h"
2 #include <sigc++/sigc++.h>
3 #include <sstream>
4 #include <functional> //For std::ref().
5 #include <cstdlib>
6
7 namespace
8 {
9 std::ostringstream result_stream;
10
11 class Base
12   : virtual public sigc::trackable
13 {
14 };
15
16 class Base2
17 {
18 public:
19   virtual ~Base2()
20   {}
21 };
22
23 class Derived
24   : virtual public Base,
25     public Base2
26 {
27 public:
28   void method()
29   {
30     result_stream << "method()";
31   }
32 };
33
34 } // end anonymous namespace
35
36 int main(int argc, char* argv[])
37 {
38   auto util = TestUtilities::get_instance();
39
40   if (!util->check_command_args(argc, argv))
41     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
42
43   auto instance = new Derived();
44   sigc::slot<void()> handler = sigc::mem_fun(*instance, &Derived::method);
45   handler();
46   util->check_result(result_stream, "method()");
47
48   auto param =
49     sigc::bind(sigc::slot<void(Derived&)>(), std::ref(*instance));
50   param();
51   util->check_result(result_stream, "");
52
53   auto ret =
54     sigc::bind_return(sigc::slot<void()>(), std::ref(*instance));
55   ret();
56   util->check_result(result_stream, "");
57
58   delete instance;
59
60   handler();
61   param();
62   ret();
63   util->check_result(result_stream, "");
64
65   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
66 }