Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
anarthal committed Feb 25, 2025
1 parent ff6d2fb commit 444ca7f
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions test/unit/test/impl/variant_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/local/stream_protocol.hpp>
#include <boost/core/span.hpp>
#include <boost/test/tools/detail/per_element_manip.hpp>
#include <boost/test/tools/detail/print_helper.hpp>
#include <boost/test/unit_test.hpp>
Expand Down Expand Up @@ -70,7 +71,7 @@ struct fixture : io_context_fixture
detail::variant_stream_state st{ctx.get_executor(), nullptr};
any_address addr;

std::array<tcp::endpoint, 2> tcp_endpoints() const
static std::array<tcp::endpoint, 2> tcp_endpoints()
{
return {
{
Expand All @@ -79,6 +80,11 @@ struct fixture : io_context_fixture
}
};
}

static tcp::resolver::results_type make_resolver_results(boost::span<const tcp::endpoint> endpoints)
{
return tcp::resolver::results_type::create(endpoints.begin(), endpoints.end(), "my_host", "1234");
}
};

BOOST_FIXTURE_TEST_CASE(tcp_success, fixture)
Expand All @@ -95,7 +101,7 @@ BOOST_FIXTURE_TEST_CASE(tcp_success, fixture)

// Resolving done: we should connect
auto endpoints = tcp_endpoints();
auto r = tcp::resolver::results_type::create(endpoints.begin(), endpoints.end(), "my_host", "1234");
auto r = make_resolver_results(endpoints);
act = algo.resume(error_code(), &r, cancellation_type_t::none);
BOOST_TEST(act.type == vsconnect_action_type::connect);
BOOST_TEST(act.data.connect == endpoints, per_element());
Expand Down Expand Up @@ -140,7 +146,7 @@ BOOST_FIXTURE_TEST_CASE(tcp_error_connect, fixture)

// Resolving done: we should connect
auto endpoints = tcp_endpoints();
auto r = tcp::resolver::results_type::create(endpoints.begin(), endpoints.end(), "my_host", "1234");
auto r = make_resolver_results(endpoints);
act = algo.resume(error_code(), &r, cancellation_type_t::none);
BOOST_TEST(act.type == vsconnect_action_type::connect);
BOOST_TEST(act.data.connect == endpoints, per_element());
Expand Down Expand Up @@ -233,12 +239,7 @@ BOOST_FIXTURE_TEST_CASE(cancellation_contains_terminal, fixture)

// Resolving finished successfully, but the cancellation state is set
auto endpoints = tcp_endpoints();
auto r = tcp::resolver::results_type::create(
endpoints.begin(),
endpoints.end(),
"my_host",
"1234"
);
auto r = make_resolver_results(endpoints);
act = algo.resume(error_code(), &r, tc.cancellation_state);
BOOST_TEST(act.type == vsconnect_action_type::none);
BOOST_TEST(act.data.err == asio::error::operation_aborted);
Expand Down Expand Up @@ -276,12 +277,7 @@ BOOST_FIXTURE_TEST_CASE(cancellation_no_terminal, fixture)

// Resolving done: we should connect
auto endpoints = tcp_endpoints();
auto r = tcp::resolver::results_type::create(
endpoints.begin(),
endpoints.end(),
"my_host",
"1234"
);
auto r = make_resolver_results(endpoints);
act = algo.resume(error_code(), &r, tc.cancellation_state);
BOOST_TEST(act.type == vsconnect_action_type::connect);
BOOST_TEST(act.data.connect == endpoints, per_element());
Expand Down

0 comments on commit 444ca7f

Please sign in to comment.