• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ska-sa / spead2 / 29335990415

14 Jul 2026 01:19PM UTC coverage: 78.647% (-0.1%) from 78.761%
29335990415

Pull #439

github

web-flow
Merge c8be01fb9 into 9ab8d39bc
Pull Request #439: Update OSes used for testing

5558 of 7067 relevant lines covered (78.65%)

119979.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/unittest_send_tcp.cpp
1
;/* Copyright 2020, 2023-2025 National Research Foundation (SARAO)
2
 *
3
 * This program is free software: you can redistribute it and/or modify it under
4
 * the terms of the GNU Lesser General Public License as published by the Free
5
 * Software Foundation, either version 3 of the License, or (at your option) any
6
 * later version.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
11
 * details.
12
 *
13
 * You should have received a copy of the GNU Lesser General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 */
16

17
/**
18
 * @file
19
 *
20
 * Unit tests for send_tcp. This is just a targeted test for features that
21
 * aren't tested by the Python unit tests.
22
 */
23

24
#include <boost/asio.hpp>
25
#include <boost/test/unit_test.hpp>
26
#include <spead2/common_thread_pool.h>
27
#include <spead2/send_tcp.h>
28

29
namespace spead2::unittest
30
{
31

32
BOOST_AUTO_TEST_SUITE(send)
33
BOOST_AUTO_TEST_SUITE(tcp)
34

35
/// Get a port number that isn't currently being listened on
36
static std::uint16_t unused_tcp_port()
1✔
37
{
38
    boost::asio::io_context context;
1✔
39
    boost::asio::ip::tcp::socket socket(context);
1✔
40
    socket.open(boost::asio::ip::tcp::v4());
1✔
41
    socket.bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::loopback(), 0));
1✔
42
    std::uint16_t port = socket.local_endpoint().port();
1✔
43
    socket.close();
1✔
44
    return port;
1✔
45
}
1✔
46

47
/* Put a heap into a stream before the connection has been established.
48
 * The connection is set up to fail, at which point we must get errors
49
 * reported.
50
 */
51
BOOST_AUTO_TEST_CASE(connect_fail)
2✔
52
{
53
    spead2::send::heap h;
1✔
54
    h.add_item(0x1234, 0x5678);
1✔
55

56
    spead2::thread_pool tp;
1✔
57
    boost::system::error_code connect_error;
1✔
58
    boost::system::error_code heap_error;
1✔
59

60
    boost::asio::ip::tcp::endpoint endpoint(
61
        boost::asio::ip::make_address_v4("127.0.0.1"),
×
62
        unused_tcp_port());
1✔
63
    spead2::send::tcp_stream stream(
64
        tp, [&](const boost::system::error_code &ec) { connect_error = ec; },
1✔
65
        {endpoint});
2✔
66
    auto handler = [&](const boost::system::error_code &ec,
1✔
67
                       [[maybe_unused]] spead2::item_pointer_t bytes_transferred)
68
    {
69
        heap_error = ec;
1✔
70
    };
2✔
71
    stream.async_send_heap(h, handler);
1✔
72
    stream.flush();
1✔
73
    BOOST_TEST(connect_error == boost::asio::error::connection_refused);
1✔
74
    BOOST_TEST(heap_error == boost::asio::error::broken_pipe);
1✔
75
}
1✔
76

77
BOOST_AUTO_TEST_SUITE_END()  // tcp
78
BOOST_AUTO_TEST_SUITE_END()  // send
79

80
} // namespace spead2::unittest
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc