Files
mqtt5/test/unit/include/test_common/test_service.hpp
Korina Šimičević 97d8a4ea86 Validate control packet size
Summary: resolves T13332

Reviewers: ivica

Reviewed By: ivica

Subscribers: miljen, iljazovic

Maniphest Tasks: T13332

Differential Revision: https://repo.mireo.local/D27000
2023-12-22 10:00:53 +01:00

76 lines
1.8 KiB
C++

#ifndef ASYNC_MQTT5_TEST_TEST_SERVICE_HPP
#define ASYNC_MQTT5_TEST_TEST_SERVICE_HPP
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/prepend.hpp>
#include <async_mqtt5/types.hpp>
#include <async_mqtt5/impl/client_service.hpp>
namespace async_mqtt5::test {
namespace asio = boost::asio;
template <
typename StreamType,
typename TlsContext = std::monostate
>
class test_service : public detail::client_service<StreamType, TlsContext> {
using error_code = boost::system::error_code;
using base = detail::client_service<StreamType, TlsContext>;
asio::any_io_executor _ex;
connack_props _test_props;
public:
test_service(const asio::any_io_executor ex)
: base(ex, {}), _ex(ex)
{}
test_service(const asio::any_io_executor ex, connack_props props)
: base(ex, {}), _ex(ex), _test_props(std::move(props))
{}
template <typename BufferType, typename CompletionToken>
decltype(auto) async_send(
const BufferType&, uint32_t, unsigned,
CompletionToken&& token
) {
auto initiation = [this](auto handler) {
auto ex = asio::get_associated_executor(handler, _ex);
asio::post(ex,
asio::prepend(std::move(handler), error_code {})
);
};
return asio::async_initiate<
CompletionToken, void (error_code)
> (std::move(initiation), token);
}
template <typename Prop>
decltype(auto) connack_prop(Prop p) {
return std::as_const(_test_props[p]);
}
template <typename Prop0, typename ...Props>
decltype(auto) connack_props(Prop0 p0, Props ...props) {
return std::make_tuple(
std::as_const(_test_props[p0]),
std::as_const(_test_props[props])...
);
}
const auto& connack_props() {
return _test_props;
}
};
} // end namespace async_mqtt5::test
#endif // ASYNC_MQTT5_TEST_TEST_SERVICE_HPP