1 | // Boost.Signals library |
2 | |
3 | // Copyright (C) Douglas Gregor 2001-2006. Use, modification and |
4 | // distribution is subject to the Boost Software License, Version |
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | |
8 | // For more information, see http://www.boost.org |
9 | |
10 | #include <boost/bind/bind.hpp> |
11 | #include <boost/shared_ptr.hpp> |
12 | #include <boost/signals2.hpp> |
13 | #define BOOST_TEST_MODULE dead_slot_test |
14 | #include <boost/test/included/unit_test.hpp> |
15 | |
16 | using namespace boost::placeholders; |
17 | |
18 | typedef boost::signals2::signal<int (int)> sig_type; |
19 | |
20 | class with_constant { |
21 | public: |
22 | with_constant(int c) : constant(c) {} |
23 | |
24 | int add(int i) { return i + constant; } |
25 | |
26 | private: |
27 | int constant; |
28 | }; |
29 | |
30 | void do_delayed_connect(boost::shared_ptr<with_constant> &wc, |
31 | sig_type& sig, |
32 | sig_type::slot_type slot) |
33 | { |
34 | // Should invalidate the slot, so that we cannot connect to it |
35 | wc.reset(); |
36 | |
37 | boost::signals2::connection c = sig.connect(slot); |
38 | BOOST_CHECK(!c.connected()); |
39 | } |
40 | |
41 | BOOST_AUTO_TEST_CASE(test_main) |
42 | { |
43 | sig_type s1; |
44 | boost::shared_ptr<with_constant> wc1(new with_constant(7)); |
45 | |
46 | do_delayed_connect(wc&: wc1, sig&: s1, slot: sig_type::slot_type(&with_constant::add, wc1.get(), _1).track(tracked: wc1)); |
47 | } |
48 | |