Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/signals/test/dead_slot_test.cpp @ 28

Last change on this file since 28 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.1 KB
Line 
1// Boost.Signals library
2
3// Copyright Douglas Gregor 2001-2003. 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
14typedef boost::signal1<int, int> sig_type;
15
16class with_constant : public boost::BOOST_SIGNALS_NAMESPACE::trackable {
17public:
18  with_constant(int c) : constant(c) {}
19
20  int add(int i) { return i + constant; }
21
22private:
23  int constant;
24};
25
26void 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(slot);
34  BOOST_CHECK(!c.connected());
35}
36
37int test_main(int, char*[])
38{
39  sig_type s1;
40  with_constant* wc1 = new with_constant(7);
41
42  do_delayed_connect(wc1, s1, boost::bind(&with_constant::add, wc1, _1));
43
44  return 0;
45}
Note: See TracBrowser for help on using the repository browser.