1//
2// append.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/append.hpp>
18
19#include <boost/asio/bind_executor.hpp>
20#include <boost/asio/io_context.hpp>
21#include <boost/asio/post.hpp>
22#include <boost/asio/system_timer.hpp>
23#include "unit_test.hpp"
24
25void append_test()
26{
27 boost::asio::io_context io1;
28 boost::asio::io_context io2;
29 boost::asio::system_timer timer1(io1);
30 int count = 0;
31
32 timer1.expires_after(expiry_time: boost::asio::chrono::seconds(0));
33 timer1.async_wait(
34 token: boost::asio::append(
35 completion_token: boost::asio::bind_executor(ex: io2.get_executor(),
36 t: [&count](boost::system::error_code, int a, int b)
37 {
38 ++count;
39 BOOST_ASIO_CHECK(a == 123);
40 BOOST_ASIO_CHECK(b == 321);
41 }), values: 123, values: 321));
42
43 BOOST_ASIO_CHECK(count == 0);
44
45 io1.run();
46
47 BOOST_ASIO_CHECK(count == 0);
48
49 io2.run();
50
51 BOOST_ASIO_CHECK(count == 1);
52}
53
54BOOST_ASIO_TEST_SUITE
55(
56 "append",
57 BOOST_ASIO_TEST_CASE(append_test)
58)
59

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