dead_slot_test.cpp 1.1 KB

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