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/test/minimal.hpp> |
11 | #include <boost/signal.hpp> |
12 | #include <boost/bind.hpp> |
13 | |
14 | typedef boost::signal1<int, int> sig_type; |
15 | |
16 | class with_constant : public boost::BOOST_SIGNALS_NAMESPACE::trackable { |
17 | public: |
18 | with_constant(int c) : constant(c) {} |
19 | |
20 | int add(int i) { return i + constant; } |
21 | |
22 | private: |
23 | int constant; |
24 | }; |
25 | |
26 | void do_delayed_connect(with_constant* wc, |
27 | sig_type& sig, |
28 | sig_type::slot_type slot) |
29 | { |
30 | // Should invalidate the slot, so that we cannot connect to it |
31 | delete wc; |
32 | |
33 | boost::BOOST_SIGNALS_NAMESPACE::connection c = sig.connect(in_slot: slot); |
34 | BOOST_CHECK(!c.connected()); |
35 | } |
36 | |
37 | int test_main(int, char*[]) |
38 | { |
39 | sig_type s1; |
40 | with_constant* wc1 = new with_constant(7); |
41 | |
42 | do_delayed_connect(wc: wc1, sig&: s1, slot: boost::bind(f: &with_constant::add, a1: wc1, a2: _1)); |
43 | |
44 | return 0; |
45 | } |
46 | |