]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/signals/test/signal_n_test.cpp
1 // Boost.Signals library
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)
8 // For more information, see http://www.boost.org
10 #include <boost/test/minimal.hpp>
11 #include <boost/signal.hpp>
15 struct max_or_default
{
16 typedef T result_type
;
17 template<typename InputIterator
>
18 typename
InputIterator::value_type
19 operator()(InputIterator first
, InputIterator last
) const
25 for (; first
!= last
; ++first
)
26 max
= (*first
> max
)? *first
: max
;
33 make_int(int n
, int cn
) : N(n
), CN(n
) {}
34 int operator()() { return N
; }
35 int operator()() const { return CN
; }
42 struct make_increasing_int
{
43 make_increasing_int() : n(N
) {}
45 int operator()() const { return n
++; }
50 int get_37() { return 37; }
62 boost::signal0
<int, max_or_default
<int>, std::string
> s0
;
63 boost::BOOST_SIGNALS_NAMESPACE::connection c2
= s0
.connect(i2
);
64 boost::BOOST_SIGNALS_NAMESPACE::connection c72
= s0
.connect("72", i72
);
65 boost::BOOST_SIGNALS_NAMESPACE::connection c62
= s0
.connect("6x", i62
);
66 boost::BOOST_SIGNALS_NAMESPACE::connection c42
= s0
.connect(i42
);
67 boost::BOOST_SIGNALS_NAMESPACE::connection c37
= s0
.connect(&get_37
);
69 BOOST_CHECK(s0() == 72);
72 BOOST_CHECK(s0() == 62);
74 c72
.disconnect(); // Double-disconnect should be safe
75 BOOST_CHECK(s0() == 62);
77 s0
.disconnect("72"); // Triple-disconect should be safe
78 BOOST_CHECK(s0() == 62);
80 // Also connect 63 in the same group as 62
81 s0
.connect("6x", i63
);
82 BOOST_CHECK(s0() == 63);
84 // Disconnect all of the 60's
86 BOOST_CHECK(s0() == 42);
89 BOOST_CHECK(s0() == 37);
92 BOOST_CHECK(s0() == 2);
95 BOOST_CHECK(s0() == 0);
99 boost::signal0
<int, max_or_default
<int> > s0
;
100 boost::BOOST_SIGNALS_NAMESPACE::connection c2
= s0
.connect(i2
);
101 boost::BOOST_SIGNALS_NAMESPACE::connection c72
= s0
.connect(i72
);
102 boost::BOOST_SIGNALS_NAMESPACE::connection c62
= s0
.connect(i62
);
103 boost::BOOST_SIGNALS_NAMESPACE::connection c42
= s0
.connect(i42
);
105 const boost::signal0
<int, max_or_default
<int> >& cs0
= s0
;
106 BOOST_CHECK(cs0() == 72);
110 make_increasing_int
<7> i7
;
111 make_increasing_int
<10> i10
;
113 boost::signal0
<int, max_or_default
<int> > s0
;
114 boost::BOOST_SIGNALS_NAMESPACE::connection c7
= s0
.connect(i7
);
115 boost::BOOST_SIGNALS_NAMESPACE::connection c10
= s0
.connect(i10
);
117 BOOST_CHECK(s0() == 10);
118 BOOST_CHECK(s0() == 11);
125 boost::signal1
<int, int, max_or_default
<int> > s1
;
127 s1
.connect(std::negate
<int>());
129 #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
131 s1
.connect(std::bind1st(std::multiplies
<int>(), 2));
135 s1
.connect(std::bind(std::multiplies
<int>(), 2, std::placeholders::_1
));
139 BOOST_CHECK(s1(1) == 2);
140 BOOST_CHECK(s1(-1) == 1);
144 test_signal_signal_connect()
146 boost::signal1
<int, int, max_or_default
<int> > s1
;
148 s1
.connect(std::negate
<int>());
150 BOOST_CHECK(s1(3) == -3);
153 boost::signal1
<int, int, max_or_default
<int> > s2
;
156 #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
158 s2
.connect(std::bind1st(std::multiplies
<int>(), 2));
159 s2
.connect(std::bind1st(std::multiplies
<int>(), -3));
163 s2
.connect(std::bind(std::multiplies
<int>(), 2, std::placeholders::_1
));
164 s2
.connect(std::bind(std::multiplies
<int>(), -3, std::placeholders::_1
));
168 BOOST_CHECK(s2(-3) == 9);
169 BOOST_CHECK(s1(3) == 6);
170 } // s2 goes out of scope and disconnects
172 BOOST_CHECK(s1(3) == -3);
177 EventCounter() : count(0) {}
191 boost::signal0
<void> s
;
194 boost::BOOST_SIGNALS_NAMESPACE::scoped_connection c
= s
.connect(boost::ref(ec
));
195 BOOST_CHECK(ec
.count
== 0);
197 BOOST_CHECK(ec
.count
== 1);
200 BOOST_CHECK(ec
.count
== 1);
204 test_main(int, char* [])
208 test_signal_signal_connect();