]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - tests/test_slot_disconnect.cc
Adjust the name of the library to match upstream
[ext/sigc++-2.0.git] / tests / test_slot_disconnect.cc
1 /* Copyright 2005, 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 namespace
12 {
13 std::ostringstream result_stream;
14
15 void Foo()
16 {
17   result_stream << "Foo";
18 }
19
20 void Bar()
21 {
22   result_stream << "Bar";
23 }
24
25 } // end anonymous namespace
26
27 int main(int argc, char* argv[])
28 {
29   auto util = TestUtilities::get_instance();
30
31   if (!util->check_command_args(argc, argv))
32     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
33
34   //Note that sigc::ptr_fun() creates a sigc::pointer_functor0.
35   sigc::slot<void> theSlot(sigc::ptr_fun(&Foo));
36   theSlot();
37   util->check_result(result_stream, "Foo");
38
39   theSlot.disconnect();
40   theSlot();
41   util->check_result(result_stream, "");
42
43   theSlot = sigc::ptr_fun(&Bar);
44   theSlot();
45   util->check_result(result_stream, "Bar");
46
47   theSlot = sigc::slot<void>(); // Assign an empty slot.
48   theSlot();
49   util->check_result(result_stream, "");
50
51   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
52 }