MCPcopy Create free account
hub / github.com/boostorg/asio / thread_pool_service_test

Function thread_pool_service_test

test/thread_pool.cpp:136–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134};
135
136void thread_pool_service_test()
137{
138 boost::asio::thread_pool pool1(1);
139 boost::asio::thread_pool pool2(1);
140 boost::asio::thread_pool pool3(1);
141
142 // Implicit service registration.
143
144 boost::asio::use_service<test_service>(pool1);
145
146 BOOST_ASIO_CHECK(boost::asio::has_service<test_service>(pool1));
147
148 test_service* svc1 = new test_service(pool1);
149 try
150 {
151 boost::asio::add_service(pool1, svc1);
152 BOOST_ASIO_ERROR("add_service did not throw");
153 }
154 catch (boost::asio::service_already_exists&)
155 {
156 }
157 delete svc1;
158
159 // Explicit service registration.
160
161 test_service& svc2 = boost::asio::make_service<test_service>(pool2);
162
163 BOOST_ASIO_CHECK(boost::asio::has_service<test_service>(pool2));
164 BOOST_ASIO_CHECK(&boost::asio::use_service<test_service>(pool2) == &svc2);
165
166 test_service* svc3 = new test_service(pool2);
167 try
168 {
169 boost::asio::add_service(pool2, svc3);
170 BOOST_ASIO_ERROR("add_service did not throw");
171 }
172 catch (boost::asio::service_already_exists&)
173 {
174 }
175 delete svc3;
176
177 // Explicit registration with invalid owner.
178
179 test_service* svc4 = new test_service(pool2);
180 try
181 {
182 boost::asio::add_service(pool3, svc4);
183 BOOST_ASIO_ERROR("add_service did not throw");
184 }
185 catch (boost::asio::invalid_service_owner&)
186 {
187 }
188 delete svc4;
189
190 BOOST_ASIO_CHECK(!boost::asio::has_service<test_service>(pool3));
191
192 // Initial service registration.
193

Callers

nothing calls this directly

Calls 2

add_serviceFunction · 0.85
get_valueMethod · 0.45

Tested by

no test coverage detected