1//
2// signal_set.cpp
3// ~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11// Disable autolinking for unit tests.
12#if !defined(BOOST_ALL_NO_LIB)
13#define BOOST_ALL_NO_LIB 1
14#endif // !defined(BOOST_ALL_NO_LIB)
15
16// Test that header file is self-contained.
17#include <boost/asio/signal_set.hpp>
18
19#include "archetypes/async_result.hpp"
20#include <boost/asio/io_context.hpp>
21#include "unit_test.hpp"
22
23//------------------------------------------------------------------------------
24
25// signal_set_compile test
26// ~~~~~~~~~~~~~~~~~~~~~~~
27// The following test checks that all public member functions on the class
28// signal_set compile and link correctly. Runtime failures are ignored.
29
30namespace signal_set_compile {
31
32void signal_handler(const boost::system::error_code&, int)
33{
34}
35
36void test()
37{
38 using namespace boost::asio;
39
40 try
41 {
42 io_context ioc;
43 const io_context::executor_type ioc_ex = ioc.get_executor();
44 archetypes::lazy_handler lazy;
45 boost::system::error_code ec;
46
47 // basic_signal_set constructors.
48
49 signal_set set1(ioc);
50 signal_set set2(ioc, 1);
51 signal_set set3(ioc, 1, 2);
52 signal_set set4(ioc, 1, 2, 3);
53
54 signal_set set5(ioc_ex);
55 signal_set set6(ioc_ex, 1);
56 signal_set set7(ioc_ex, 1, 2);
57 signal_set set8(ioc_ex, 1, 2, 3);
58
59 // basic_io_object functions.
60
61 signal_set::executor_type ex = set1.get_executor();
62 (void)ex;
63
64 // basic_signal_set functions.
65
66 set1.add(signal_number: 1);
67 set1.add(signal_number: 1, ec);
68
69 set1.add(signal_number: 1, f: signal_set::flags::dont_care);
70 set1.add(signal_number: 1, f: signal_set::flags::dont_care, ec);
71
72 set1.remove(signal_number: 1);
73 set1.remove(signal_number: 1, ec);
74
75 set1.clear();
76 set1.clear(ec);
77
78 set1.cancel();
79 set1.cancel(ec);
80
81 set1.async_wait(token: &signal_handler);
82 int i = set1.async_wait(token&: lazy);
83 (void)i;
84 }
85 catch (std::exception&)
86 {
87 }
88}
89
90} // namespace signal_set_compile
91
92//------------------------------------------------------------------------------
93
94BOOST_ASIO_TEST_SUITE
95(
96 "signal_set",
97 BOOST_ASIO_COMPILE_TEST_CASE(signal_set_compile::test)
98)
99

source code of boost/libs/asio/test/signal_set.cpp