// // Copyright (c) 2023-2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "test_common/test_broker.hpp" #include "test_common/extra_deps.hpp" #include #include #include #include #include #include #include #include #include #include #include using namespace boost::mqtt5; struct good_authenticator { good_authenticator() = default; template decltype(auto) async_auth( auth_step_e step, std::string data, CompletionToken&& token ) { using error_code = boost::system::error_code; using Signature = void (error_code, std::string); auto initiate = [](auto, auth_step_e, std::string) {}; return asio::async_initiate( initiate, token, step, std::move(data) ); } std::string_view method() const { return "method"; } }; struct bad_authenticator { bad_authenticator() = default; void async_auth(std::string /* data */) {} std::string_view method() const { return "method"; } }; BOOST_STATIC_ASSERT(detail::is_authenticator); BOOST_STATIC_ASSERT(!detail::is_authenticator); namespace asio = boost::asio; using tcp_layer = asio::ip::tcp::socket; BOOST_STATIC_ASSERT(!detail::has_next_layer); BOOST_STATIC_ASSERT(!detail::has_tls_layer); BOOST_STATIC_ASSERT(!detail::has_tls_handshake); BOOST_STATIC_ASSERT(!detail::has_ws_handshake); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); void tcp_layers_test() { asio::system_executor ex; tcp_layer layer(ex); detail::next_layer_type& nlayer = detail::next_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); detail::lowest_layer_type& llayer = detail::lowest_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); } #ifdef BOOST_MQTT5_EXTRA_DEPS namespace beast = boost::beast; using tls_layer = asio::ssl::stream; using websocket_tcp_layer = beast::websocket::stream; using websocket_tls_layer = beast::websocket::stream; BOOST_STATIC_ASSERT(detail::has_next_layer); BOOST_STATIC_ASSERT(detail::has_tls_layer); BOOST_STATIC_ASSERT(detail::has_tls_handshake); BOOST_STATIC_ASSERT(!detail::has_ws_handshake); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); BOOST_STATIC_ASSERT(detail::has_next_layer); BOOST_STATIC_ASSERT(!detail::has_tls_layer); BOOST_STATIC_ASSERT(!detail::has_tls_handshake); BOOST_STATIC_ASSERT(detail::has_ws_handshake); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); BOOST_STATIC_ASSERT(detail::has_next_layer); BOOST_STATIC_ASSERT(detail::has_tls_layer); BOOST_STATIC_ASSERT(!detail::has_tls_handshake); BOOST_STATIC_ASSERT(detail::has_ws_handshake); BOOST_STATIC_ASSERT(std::is_same_v, tls_layer>); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); void tls_layers_test() { asio::system_executor ex; asio::ssl::context ctx(asio::ssl::context::tls_client); tls_layer layer(ex, ctx); detail::next_layer_type& nlayer = detail::next_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); detail::lowest_layer_type& llayer = detail::lowest_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); } void websocket_tcp_layers_test() { asio::system_executor ex; websocket_tcp_layer layer(ex); detail::next_layer_type& nlayer = detail::next_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); detail::lowest_layer_type& llayer = detail::lowest_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); } void websocket_tls_layers_test() { asio::system_executor ex; asio::ssl::context ctx(asio::ssl::context::tls_client); websocket_tls_layer layer(ex, ctx); detail::next_layer_type& nlayer = detail::next_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tls_layer>); detail::lowest_layer_type& llayer = detail::lowest_layer(layer); BOOST_STATIC_ASSERT(std::is_same_v, tcp_layer>); } #endif // BOOST_MQTT5_EXTRA_DEPS