]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - tests/test_signal_move.cc
Adjust the name of the library to match upstream
[ext/sigc++-2.0.git] / tests / test_signal_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++/trackable.h>
7 #include <sigc++/signal.h>
8 #include <sigc++/functors/ptr_fun.h>
9 #include <sigc++/functors/mem_fun.h>
10 #include <string>
11 #include <cstdlib>
12
13 namespace
14 {
15 std::ostringstream result_stream;
16
17 int foo(int i)
18 {
19   result_stream << "foo(int " << i << ")";
20   return 1;
21 }
22
23 } // end anonymous namespace
24
25 int main(int argc, char* argv[])
26 {
27   auto util = TestUtilities::get_instance();
28
29   if (!util->check_command_args(argc, argv))
30     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
31
32   // signal
33   sigc::signal<int, int> sig;
34   sig.connect(sigc::ptr_fun(&foo));
35   sig(1);
36   util->check_result(result_stream, "foo(int 1)");
37
38   //Test the move constructor:
39   sigc::signal<int, int> sig2(std::move(sig));
40   sig(-2);
41   sig2(2);
42   util->check_result(result_stream, "foo(int 2)");
43
44   //Test the move assignment operator:
45   sigc::signal<int, int> sig3;
46   sig3 = std::move(sig2);
47   sig2(-3);
48   sig3(3);
49   util->check_result(result_stream, "foo(int 3)");
50
51   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
52 }