summaryrefslogtreecommitdiff
path: root/tests/test_signal_move.cc
blob: 83a6316d07f85deb6d295d17e3dbfa650e78800a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Copyright 2015 - 2016, The libsigc++ Development Team
 *  Assigned to public domain.  Use as you wish without restriction.
 */

#include "testutilities.h"
#include <sigc++/trackable.h>
#include <sigc++/signal.h>

namespace
{
std::ostringstream result_stream;

int
foo(int i)
{
  result_stream << "foo(int " << i << ")";
  return 1;
}

} // end anonymous namespace

int
main(int argc, char* argv[])
{
  auto util = TestUtilities::get_instance();

  if (!util->check_command_args(argc, argv))
    return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;

  // signal
  sigc::signal<int(int)> sig;
  sig.connect(sigc::ptr_fun(&foo));
  sig(1);
  util->check_result(result_stream, "foo(int 1)");

  // Test the move constructor:
  sigc::signal<int(int)> sig2(std::move(sig));
  sig(-2); // Test that the moved-from slot does nothing.
  sig2(2);
  util->check_result(result_stream, "foo(int 2)");

  // Test the move assignment operator:
  sigc::signal<int(int)> sig3;
  sig3 = std::move(sig2);
  sig2(-3); // Test that the moved-from slot does nothing.
  sig3(3);
  util->check_result(result_stream, "foo(int 3)");

  return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}