]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - tests/test_slot_move.cc
Adjust the name of the library to match upstream
[ext/sigc++-2.0.git] / tests / test_slot_move.cc
1 /* Copyright 2015, The libsigc++ Development Team
2  *  Assigned to public domain.  Use as you wish without restriction.
3  */
4
5 #include "testutilities.h"
6 #include <sigc++/functors/slot.h>
7 #include <sstream>
8 #include <string>
9 #include <cstdlib>
10
11 //The Tru64 compiler seems to need this to avoid an unresolved symbol
12 //See bug #161503
13 #include <new>
14
15 namespace
16 {
17 std::ostringstream result_stream;
18
19 class foo
20 {
21 public:
22   void operator()(int i)
23   {
24     result_stream << "foo(int " << i << ")";
25   }
26
27   void operator()(std::string& str)
28   {
29     result_stream << "foo(string '" << str << "') ";
30     str="foo was here";
31   }
32
33   void operator()(int, int)
34   {
35     result_stream << "foo(int, int)";
36   }
37 };
38
39 } // end anonymous namespace
40
41 int main(int argc, char* argv[])
42 {
43   auto util = TestUtilities::get_instance();
44
45   if (!util->check_command_args(argc, argv))
46     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
47
48   // simple test
49   sigc::slot<void,int> s1 = foo();
50   s1(1);
51   util->check_result(result_stream, "foo(int 1)");
52
53   // test move constructor:
54   sigc::slot<void,int> s2(std::move(s1));
55   s1(-2);
56   s2(2);
57   util->check_result(result_stream, "foo(int 2)");
58
59   // test move assignment:
60   sigc::slot<void,int> s3;
61   s3 = std::move(s2);
62   s2(-3);
63   s3(3);
64   util->check_result(result_stream, "foo(int 3)");
65
66   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
67 }