]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/signals/test/deletion_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 static boost::BOOST_SIGNALS_NAMESPACE::connection connections
[5];
17 static std::string test_output
;
19 struct remove_connection
{
20 explicit remove_connection(int v
= 0, int i
= -1) : value(v
), idx(i
) {}
22 void operator()() const {
24 connections
[idx
].disconnect();
27 std::cout
<< value
<< " ";
29 test_output
+= static_cast<char>(value
+ '0');
36 bool operator==(const remove_connection
& x
, const remove_connection
& y
)
37 { return x
.value
== y
.value
&& x
.idx
== y
.idx
; }
42 boost::signal0
<void> s0
;
44 connections
[0] = s0
.connect(remove_connection(0));
45 connections
[1] = s0
.connect(remove_connection(1));
46 connections
[2] = s0
.connect(remove_connection(2, 2));
47 connections
[3] = s0
.connect(remove_connection(3));
49 std::cout
<< "Deleting 2" << std::endl
;
52 s0(); std::cout
<< std::endl
;
53 BOOST_CHECK(test_output
== "0123");
56 s0(); std::cout
<< std::endl
;
57 BOOST_CHECK(test_output
== "013");
59 s0
.disconnect_all_slots();
60 BOOST_CHECK(s0
.empty());
62 connections
[0] = s0
.connect(remove_connection(0));
63 connections
[1] = s0
.connect(remove_connection(1));
64 connections
[2] = s0
.connect(remove_connection(2));
65 connections
[3] = s0
.connect(remove_connection(3, 3));
67 std::cout
<< "Deleting 3" << std::endl
;
70 s0(); std::cout
<< std::endl
;
71 BOOST_CHECK(test_output
== "0123");
74 s0(); std::cout
<< std::endl
;
75 BOOST_CHECK(test_output
== "012");
77 s0
.disconnect_all_slots();
78 BOOST_CHECK(s0
.num_slots() == 0);
80 connections
[0] = s0
.connect(remove_connection(0, 0));
81 connections
[1] = s0
.connect(remove_connection(1));
82 connections
[2] = s0
.connect(remove_connection(2));
83 connections
[3] = s0
.connect(remove_connection(3));
85 std::cout
<< "Deleting 0" << std::endl
;
88 s0(); std::cout
<< std::endl
;
89 BOOST_CHECK(test_output
== "0123");
92 s0(); std::cout
<< std::endl
;
93 BOOST_CHECK(test_output
== "123");
95 std::cout
<< "Blocking 2" << std::endl
;
97 connections
[2].block();
99 s0(); std::cout
<< std::endl
;
100 BOOST_CHECK(test_output
== "13");
102 std::cout
<< "Unblocking 2" << std::endl
;
104 connections
[2].unblock();
106 s0(); std::cout
<< std::endl
;
107 BOOST_CHECK(test_output
== "123");
109 s0
.disconnect_all_slots();
110 BOOST_CHECK(s0
.empty());
112 connections
[0] = s0
.connect(remove_connection(0, 0));
113 connections
[1] = s0
.connect(remove_connection(1, 1));
114 connections
[2] = s0
.connect(remove_connection(2, 2));
115 connections
[3] = s0
.connect(remove_connection(3, 3));
117 std::cout
<< "Mass suicide" << std::endl
;
120 s0(); std::cout
<< std::endl
;
121 BOOST_CHECK(test_output
== "0123");
124 s0(); std::cout
<< std::endl
;
125 BOOST_CHECK(test_output
== "");
131 boost::signal0
<void> s0
;
133 connections
[0] = s0
.connect(remove_connection(0));
134 connections
[1] = s0
.connect(remove_connection(1, 0));
135 connections
[2] = s0
.connect(remove_connection(2));
136 connections
[3] = s0
.connect(remove_connection(3));
138 std::cout
<< "1 removes 0" << std::endl
;
141 s0(); std::cout
<< std::endl
;
142 BOOST_CHECK(test_output
== "0123");
145 s0(); std::cout
<< std::endl
;
146 BOOST_CHECK(test_output
== "123");
148 s0
.disconnect_all_slots();
149 BOOST_CHECK(s0
.empty());
151 connections
[0] = s0
.connect(remove_connection(0));
152 connections
[1] = s0
.connect(remove_connection(1));
153 connections
[2] = s0
.connect(remove_connection(2));
154 connections
[3] = s0
.connect(remove_connection(3, 2));
156 std::cout
<< "3 removes 2" << std::endl
;
159 s0(); std::cout
<< std::endl
;
160 BOOST_CHECK(test_output
== "0123");
163 s0(); std::cout
<< std::endl
;
164 BOOST_CHECK(test_output
== "013");
170 boost::signal0
<void> s0
;
172 connections
[0] = s0
.connect(remove_connection(0, 1));
173 connections
[1] = s0
.connect(remove_connection(1));
174 connections
[2] = s0
.connect(remove_connection(2));
175 connections
[3] = s0
.connect(remove_connection(3));
177 std::cout
<< "0 removes 1" << std::endl
;
180 s0(); std::cout
<< std::endl
;
181 BOOST_CHECK(test_output
== "023");
184 s0(); std::cout
<< std::endl
;
185 BOOST_CHECK(test_output
== "023");
187 s0
.disconnect_all_slots();
188 BOOST_CHECK(s0
.empty());
190 connections
[0] = s0
.connect(remove_connection(0));
191 connections
[1] = s0
.connect(remove_connection(1, 3));
192 connections
[2] = s0
.connect(remove_connection(2));
193 connections
[3] = s0
.connect(remove_connection(3));
195 std::cout
<< "1 removes 3" << std::endl
;
198 s0(); std::cout
<< std::endl
;
199 BOOST_CHECK(test_output
== "012");
202 s0(); std::cout
<< std::endl
;
203 BOOST_CHECK(test_output
== "012");
209 boost::signal0
<void> s0
;
211 connections
[0] = s0
.connect(remove_connection(0, 1));
212 connections
[1] = s0
.connect(remove_connection(1, 1));
213 connections
[2] = s0
.connect(remove_connection(2, 0));
214 connections
[3] = s0
.connect(remove_connection(3, 2));
216 std::cout
<< "0 removes 1, 2 removes 0, 3 removes 2" << std::endl
;
219 s0(); std::cout
<< std::endl
;
220 BOOST_CHECK(test_output
== "023");
223 s0(); std::cout
<< std::endl
;
224 BOOST_CHECK(test_output
== "3");
228 test_disconnect_equal()
230 boost::signal0
<void> s0
;
232 connections
[0] = s0
.connect(remove_connection(0));
233 connections
[1] = s0
.connect(remove_connection(1));
234 connections
[2] = s0
.connect(remove_connection(2));
235 connections
[3] = s0
.connect(remove_connection(3));
237 std::cout
<< "Deleting 2" << std::endl
;
240 s0(); std::cout
<< std::endl
;
241 BOOST_CHECK(test_output
== "0123");
243 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
244 connections
[2].disconnect();
246 s0
.disconnect(remove_connection(2));
250 s0(); std::cout
<< std::endl
;
251 BOOST_CHECK(test_output
== "013");
254 int test_main(int, char* [])
260 test_disconnect_equal();