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

Function io_context_service_test

test/io_context.cpp:321–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319};
320
321void io_context_service_test()
322{
323 boost::asio::io_context ioc1;
324 boost::asio::io_context ioc2;
325 boost::asio::io_context ioc3;
326
327 // Implicit service registration.
328
329 boost::asio::use_service<test_service>(ioc1);
330
331 BOOST_ASIO_CHECK(boost::asio::has_service<test_service>(ioc1));
332
333 test_service* svc1 = new test_service(ioc1);
334 try
335 {
336 boost::asio::add_service(ioc1, svc1);
337 BOOST_ASIO_ERROR("add_service did not throw");
338 }
339 catch (boost::asio::service_already_exists&)
340 {
341 }
342 delete svc1;
343
344 // Explicit service registration.
345
346 test_service* svc2 = new test_service(ioc2);
347 boost::asio::add_service(ioc2, svc2);
348
349 BOOST_ASIO_CHECK(boost::asio::has_service<test_service>(ioc2));
350 BOOST_ASIO_CHECK(&boost::asio::use_service<test_service>(ioc2) == svc2);
351
352 test_service* svc3 = new test_service(ioc2);
353 try
354 {
355 boost::asio::add_service(ioc2, svc3);
356 BOOST_ASIO_ERROR("add_service did not throw");
357 }
358 catch (boost::asio::service_already_exists&)
359 {
360 }
361 delete svc3;
362
363 // Explicit registration with invalid owner.
364
365 test_service* svc4 = new test_service(ioc2);
366 try
367 {
368 boost::asio::add_service(ioc3, svc4);
369 BOOST_ASIO_ERROR("add_service did not throw");
370 }
371 catch (boost::asio::invalid_service_owner&)
372 {
373 }
374 delete svc4;
375
376 BOOST_ASIO_CHECK(!boost::asio::has_service<test_service>(ioc3));
377
378 // Initial service registration.

Callers

nothing calls this directly

Calls 2

add_serviceFunction · 0.85
get_valueMethod · 0.45

Tested by

no test coverage detected