File: test_slot_disconnect.cc

package info (click to toggle)
libsigc%2B%2B-3.0 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: cpp: 6,500; xml: 340; makefile: 194; python: 148; sh: 21
file content (52 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (2)
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
51
52
/* Copyright 2005 - 2016, The libsigc++ Development Team
 *  Assigned to public domain.  Use as you wish without restriction.
 */

#include "testutilities.h"
#include <sigc++/functors/slot.h>

namespace
{
std::ostringstream result_stream;

void
Foo()
{
  result_stream << "Foo";
}

void
Bar()
{
  result_stream << "Bar";
}

} // 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;

  // Note that sigc::ptr_fun() creates a sig::pointer_functor.
  sigc::slot<void()> theSlot(sigc::ptr_fun(&Foo));
  theSlot();
  util->check_result(result_stream, "Foo");

  theSlot.disconnect();
  theSlot();
  util->check_result(result_stream, "");

  theSlot = sigc::ptr_fun(&Bar);
  theSlot();
  util->check_result(result_stream, "Bar");

  theSlot = sigc::slot<void()>(); // Assign an empty slot.
  theSlot();
  util->check_result(result_stream, "");

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