diff --git a/README.md b/README.md index 7dcb307..341a4b8 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Using the library 1. Download [Boost](https://www.boost.org/users/download/), and add it to your include path. 2. If you use SSL, download [OpenSSL](https://www.openssl.org/), link the library and add it to your include path. -3. Additionally, you can add Async.MQTT5's `include` folder to your include path. +3. Add Async.MQTT5's `include` folder to your include path. You can compile the example below with the following command line on Linux: diff --git a/example/hello_world_over_websocket_tls.cpp b/example/hello_world_over_websocket_tls.cpp index 6ff8b8f..49c62ad 100644 --- a/example/hello_world_over_websocket_tls.cpp +++ b/example/hello_world_over_websocket_tls.cpp @@ -14,29 +14,10 @@ #include #include +#include // async_teardown specialization for websocket ssl stream #include -namespace boost::beast::websocket { - -// boost::beast::websocket::async_teardown is a free function designed to initiate the asynchronous teardown of a connection. -// The specific behaviour of this function is based on the NextLayer type (Socket type) used to create the ``__WEBSOCKET_STREAM__``. -// ``__Beast__`` library includes an implementation of this function for ``__TCP_SOCKET__``. -// However, the callers are responsible for providing a suitable overload of this function for any other type, -// such as ``__SSL_STREAM__`` as shown in this example. -// See ``__BEAST_ASYNC_TEARDOWN__`` for more information. -template -void async_teardown( - boost::beast::role_type role, - asio::ssl::stream& stream, - TeardownHandler&& handler -) { - return stream.async_shutdown(std::forward(handler)); -} - -} // end namespace boost::beast::websocket - - // External customization point. namespace async_mqtt5 { @@ -51,7 +32,7 @@ struct tls_handshake_type> { template void assign_tls_sni( const authority_path& ap, - boost::asio::ssl::context& ctx, + boost::asio::ssl::context& /*ctx*/, boost::asio::ssl::stream& stream ) { SSL_set_tlsext_host_name(stream.native_handle(), ap.host.c_str()); diff --git a/test/include/test_common/protocol_logging.hpp b/test/include/test_common/protocol_logging.hpp deleted file mode 100644 index 61d1d52..0000000 --- a/test/include/test_common/protocol_logging.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (c) 2023-2024 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) -// - -#ifndef ASYNC_MQTT5_TEST_PROTOCOL_LOGGING_HPP -#define ASYNC_MQTT5_TEST_PROTOCOL_LOGGING_HPP - -#include - -namespace async_mqtt5::test { - -inline bool& logging_enabled() { - static bool enabled = false; - return enabled; -} - -inline void log(const std::string& message) { - if (logging_enabled()) - fprintf(stderr, "%s\n", message.c_str()); -} - - -} // end namespace async_mqtt5::test - -#endif // ASYNC_MQTT5_TEST_PROTOCOL_LOGGING_HPP diff --git a/test/include/test_common/test_broker.hpp b/test/include/test_common/test_broker.hpp index 860b047..a921470 100644 --- a/test/include/test_common/test_broker.hpp +++ b/test/include/test_common/test_broker.hpp @@ -8,6 +8,12 @@ #ifndef ASYNC_MQTT5_TEST_TEST_BROKER_HPP #define ASYNC_MQTT5_TEST_TEST_BROKER_HPP +#include +#include + +#include +#include +#include #include #include #include @@ -17,18 +23,21 @@ #include #include +#include +#include #include +#include +#include #include #include - #include +#include +#include #include #include "test_common/message_exchange.hpp" #include "test_common/packet_util.hpp" -#include "test_common/protocol_logging.hpp" - namespace async_mqtt5::test { @@ -157,16 +166,15 @@ class test_broker : public asio::execution_context::service { size_t buffers_size = std::distance( asio::buffer_sequence_begin(buffers), asio::buffer_sequence_end(buffers) ); - BOOST_CHECK_EQUAL(buffers_size, expected.size()); + BOOST_TEST(buffers_size == expected.size()); size_t num_packets = std::min(buffers_size, expected.size()); auto it = asio::buffer_sequence_begin(buffers); for (size_t i = 0; i < num_packets; ++i, ++it) { - BOOST_CHECK_EQUAL(it->size(), expected[i].size()); + BOOST_TEST(it->size() == expected[i].size()); size_t len = std::min(it->size(), expected[i].size()); if (memcmp(it->data(), expected[i].data(), len)) - BOOST_CHECK_MESSAGE( - false, + BOOST_TEST_MESSAGE( concat_strings( "Packet mismatch!\nExpected: ", to_readable_packet(expected[i]), @@ -176,12 +184,9 @@ class test_broker : public asio::execution_context::service { ); } } else - BOOST_CHECK_MESSAGE( - false, - concat_strings( - "Broker side did not expect: ", - boost::algorithm::join(to_readable_packets(buffers), ",") - ) + BOOST_TEST_MESSAGE( + "Broker side did not expect: " << + boost::algorithm::join(to_readable_packets(buffers), ",") ); auto complete_op = reply_action ? diff --git a/test/integration/async_sender.cpp b/test/integration/async_sender.cpp index 2597ea3..c9eca3b 100644 --- a/test/integration/async_sender.cpp +++ b/test/integration/async_sender.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/test/integration/client.cpp b/test/integration/client.cpp index ff5f408..c48c406 100644 --- a/test/integration/client.cpp +++ b/test/integration/client.cpp @@ -20,24 +20,12 @@ #include #include +#include // async_teardown specialization for websocket ssl stream #include #include -namespace boost::beast::websocket { - -template -void async_teardown( - boost::beast::role_type /* role */, - asio::ssl::stream& stream, - TeardownHandler&& handler -) { - return stream.async_shutdown(std::forward(handler)); -} - -} // end namespace boost::beast::websocket - namespace async_mqtt5 { template diff --git a/test/integration/ping.cpp b/test/integration/ping.cpp index bce2105..ca3d1ff 100644 --- a/test/integration/ping.cpp +++ b/test/integration/ping.cpp @@ -81,7 +81,7 @@ void run_test( }); ioc.run(); - BOOST_CHECK(broker.received_all_expected()); + BOOST_TEST(broker.received_all_expected()); } BOOST_FIXTURE_TEST_CASE(ping_pong_client_ka, shared_test_data) { diff --git a/test/integration/re_authentication.cpp b/test/integration/re_authentication.cpp index 3c84103..aacffce 100644 --- a/test/integration/re_authentication.cpp +++ b/test/integration/re_authentication.cpp @@ -99,7 +99,7 @@ void run_test( }); ioc.run(); - BOOST_CHECK(broker.received_all_expected()); + BOOST_TEST(broker.received_all_expected()); } BOOST_FIXTURE_TEST_CASE(successful_re_auth, shared_test_data) { diff --git a/test/integration/sub_unsub.cpp b/test/integration/sub_unsub.cpp index 2de5884..1e4b872 100644 --- a/test/integration/sub_unsub.cpp +++ b/test/integration/sub_unsub.cpp @@ -93,9 +93,9 @@ void run_test(test::msg_exchange broker_side) { [&handlers_called, &c](error_code ec, std::vector rcs, suback_props) { ++handlers_called; - BOOST_CHECK(!ec); - BOOST_ASSERT(rcs.size() == 1); - BOOST_CHECK_EQUAL(rcs[0], reason_codes::granted_qos_0); + BOOST_TEST(!ec); + BOOST_TEST_REQUIRE(rcs.size() == 1); + BOOST_TEST(rcs[0] == reason_codes::granted_qos_0); c.cancel(); } @@ -106,17 +106,17 @@ void run_test(test::msg_exchange broker_side) { [&handlers_called, &c](error_code ec, std::vector rcs, unsuback_props) { ++handlers_called; - BOOST_CHECK(!ec); - BOOST_ASSERT(rcs.size() == 1); - BOOST_CHECK_EQUAL(rcs[0], reason_codes::success); + BOOST_TEST(!ec); + BOOST_TEST_REQUIRE(rcs.size() == 1); + BOOST_TEST(rcs[0] == reason_codes::success); c.cancel(); } ); ioc.run_for(5s); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); - BOOST_CHECK(broker.received_all_expected()); + BOOST_TEST(handlers_called == expected_handlers_called); + BOOST_TEST(broker.received_all_expected()); } // subscribe @@ -423,9 +423,9 @@ void run_cancellation_test(test::msg_exchange broker_side) { [&handlers_called, &c](error_code ec, std::vector rcs, suback_props) { ++handlers_called; - BOOST_CHECK(ec == asio::error::operation_aborted); - BOOST_ASSERT(rcs.size() == 1); - BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty); + BOOST_TEST(ec == asio::error::operation_aborted); + BOOST_TEST_REQUIRE(rcs.size() == 1); + BOOST_TEST(rcs[0] == reason_codes::empty); c.cancel(); } @@ -439,9 +439,9 @@ void run_cancellation_test(test::msg_exchange broker_side) { [&handlers_called, &c](error_code ec, std::vector rcs, unsuback_props) { ++handlers_called; - BOOST_CHECK(ec == asio::error::operation_aborted); - BOOST_ASSERT(rcs.size() == 1); - BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty); + BOOST_TEST(ec == asio::error::operation_aborted); + BOOST_TEST_REQUIRE(rcs.size() == 1); + BOOST_TEST(rcs[0] == reason_codes::empty); c.cancel(); } @@ -451,8 +451,8 @@ void run_cancellation_test(test::msg_exchange broker_side) { cancel_signal.emit(asio::cancellation_type::total); ioc.run_for(2s); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); - BOOST_CHECK(broker.received_all_expected()); + BOOST_TEST(handlers_called == expected_handlers_called); + BOOST_TEST(broker.received_all_expected()); } BOOST_FIXTURE_TEST_CASE(cancel_resending_subscribe, shared_test_data) { diff --git a/test/src/run_tests.cpp b/test/src/run_tests.cpp index 6971e19..700d06d 100644 --- a/test/src/run_tests.cpp +++ b/test/src/run_tests.cpp @@ -9,12 +9,9 @@ #include -#include - boost::unit_test::test_suite* init_tests( int /*argc*/, char* /*argv*/[] ) { - async_mqtt5::test::logging_enabled() = false; return nullptr; } diff --git a/test/unit/connect_op.cpp b/test/unit/connect_op.cpp index 1607a93..18cb938 100644 --- a/test/unit/connect_op.cpp +++ b/test/unit/connect_op.cpp @@ -69,8 +69,8 @@ void run_unit_test( ).perform(eps, ap); ioc.run_for(1s); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); - BOOST_CHECK(broker.received_all_expected()); + BOOST_TEST(handlers_called == expected_handlers_called); + BOOST_TEST(broker.received_all_expected()); } void run_unit_test( @@ -121,7 +121,7 @@ BOOST_FIXTURE_TEST_CASE(fail_to_send_connect, shared_test_data) { .complete_with(fail, after(2ms)); auto handler = [&](error_code ec) { - BOOST_CHECK(ec == fail); + BOOST_TEST(ec == fail); }; run_unit_test(std::move(broker_side), std::move(handler)); diff --git a/test/unit/serialization.cpp b/test/unit/serialization.cpp index a8c9697..9fb63e9 100644 --- a/test/unit/serialization.cpp +++ b/test/unit/serialization.cpp @@ -83,51 +83,51 @@ BOOST_AUTO_TEST_CASE(test_connect) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_connect(remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [client_id_, uname_, password_, keep_alive_, clean_start_, cprops_, w_] = *rv; - BOOST_CHECK_EQUAL(client_id_, client_id); - BOOST_CHECK(uname_); - BOOST_CHECK_EQUAL(*uname_, uname); + BOOST_TEST(client_id_ == client_id); + BOOST_TEST_REQUIRE(uname_.has_value()); + BOOST_TEST(*uname_ == uname); BOOST_CHECK(password_ == password); - BOOST_CHECK_EQUAL(keep_alive_, keep_alive); - BOOST_CHECK_EQUAL(clean_start_, clean_start); + BOOST_TEST(keep_alive_ == keep_alive); + BOOST_TEST(clean_start_ == clean_start); cprops_.visit([](const auto& prop, const auto&) { - (void)prop; BOOST_ASSERT(prop); + (void)prop; BOOST_TEST_REQUIRE(prop); return true; }); - BOOST_CHECK_EQUAL(*cprops_[prop::session_expiry_interval], session_expiry_interval); - BOOST_CHECK_EQUAL(*cprops_[prop::receive_maximum], receive_max); - BOOST_CHECK_EQUAL(*cprops_[prop::maximum_packet_size], maximum_packet_size); - BOOST_CHECK_EQUAL(*cprops_[prop::topic_alias_maximum], topic_alias_max); - BOOST_CHECK_EQUAL(*cprops_[prop::request_response_information], request_response_information); - BOOST_CHECK_EQUAL(*cprops_[prop::request_problem_information], request_problem_information); - BOOST_ASSERT(cprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(cprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(cprops_[prop::user_property][0].second, user_property_2); - BOOST_CHECK_EQUAL(*cprops_[prop::authentication_method], auth_method); - BOOST_CHECK_EQUAL(*cprops_[prop::authentication_data], auth_data); - - BOOST_CHECK(w_); - - BOOST_CHECK_EQUAL((*w_).topic(), will_topic); - BOOST_CHECK_EQUAL((*w_).message(), will_message); - - (*w_).visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*(*w_)[prop::will_delay_interval], will_delay_interval); - BOOST_CHECK_EQUAL(*(*w_)[prop::payload_format_indicator], will_payload_format_indicator); - BOOST_CHECK_EQUAL(*(*w_)[prop::message_expiry_interval], will_message_expiry_interval); - BOOST_CHECK_EQUAL(*(*w_)[prop::content_type], will_content_type); - BOOST_CHECK_EQUAL(*(*w_)[prop::response_topic], will_response_topic); - BOOST_CHECK_EQUAL(*(*w_)[prop::correlation_data], will_correlation_data); - BOOST_ASSERT((*w_)[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL((*w_)[prop::user_property][0].first, will_user_property_1); - BOOST_CHECK_EQUAL((*w_)[prop::user_property][0].second, will_user_property_2); + BOOST_TEST(*cprops_[prop::session_expiry_interval] == session_expiry_interval); + BOOST_TEST(*cprops_[prop::receive_maximum] == receive_max); + BOOST_TEST(*cprops_[prop::maximum_packet_size] == maximum_packet_size); + BOOST_TEST(*cprops_[prop::topic_alias_maximum] == topic_alias_max); + BOOST_TEST(*cprops_[prop::request_response_information] == request_response_information); + BOOST_TEST(*cprops_[prop::request_problem_information] == request_problem_information); + BOOST_TEST_REQUIRE(cprops_[prop::user_property].size() == 1); + BOOST_TEST(cprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(cprops_[prop::user_property][0].second == user_property_2); + BOOST_TEST(*cprops_[prop::authentication_method] == auth_method); + BOOST_TEST(*cprops_[prop::authentication_data] == auth_data); + + BOOST_TEST_REQUIRE(w_.has_value()); + const auto& will = *w_; + BOOST_TEST((will).topic() == will_topic); + BOOST_TEST((will).message() == will_message); + + (will).visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*(will)[prop::will_delay_interval] == will_delay_interval); + BOOST_TEST(*(will)[prop::payload_format_indicator] == will_payload_format_indicator); + BOOST_TEST(*(will)[prop::message_expiry_interval] == will_message_expiry_interval); + BOOST_TEST(*(will)[prop::content_type] == will_content_type); + BOOST_TEST(*(will)[prop::response_topic] == will_response_topic); + BOOST_TEST(*(will)[prop::correlation_data] == will_correlation_data); + BOOST_TEST_REQUIRE((will)[prop::user_property].size() == 1); + BOOST_TEST((will)[prop::user_property][0].first == will_user_property_1); + BOOST_TEST((will)[prop::user_property][0].second == will_user_property_2); } BOOST_AUTO_TEST_CASE(test_connack) { @@ -177,36 +177,36 @@ BOOST_AUTO_TEST_CASE(test_connack) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_connack(remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [session_present_, reason_code_, cprops_] = *rv; - BOOST_CHECK_EQUAL(session_present_, session_present); - BOOST_CHECK_EQUAL(reason_code_, reason_code); - - cprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*cprops_[prop::session_expiry_interval], session_expiry_interval); - BOOST_CHECK_EQUAL(*cprops_[prop::receive_maximum], receive_maximum); - BOOST_CHECK_EQUAL(*cprops_[prop::maximum_qos], max_qos); - BOOST_CHECK_EQUAL(*cprops_[prop::retain_available], retain_available); - BOOST_CHECK_EQUAL(*cprops_[prop::maximum_packet_size], maximum_packet_sz); - BOOST_CHECK_EQUAL(*cprops_[prop::assigned_client_identifier], assigned_client_id); - BOOST_CHECK_EQUAL(*cprops_[prop::topic_alias_maximum], topic_alias_max); - BOOST_CHECK_EQUAL(*cprops_[prop::reason_string], reason_string); - BOOST_ASSERT(cprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(cprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(cprops_[prop::user_property][0].second, user_property_2); - BOOST_CHECK_EQUAL(*cprops_[prop::wildcard_subscription_available], wildcard_sub); - BOOST_CHECK_EQUAL(*cprops_[prop::subscription_identifier_available], sub_id); - BOOST_CHECK_EQUAL(*cprops_[prop::shared_subscription_available], shared_sub); - BOOST_CHECK_EQUAL(*cprops_[prop::server_keep_alive], server_keep_alive); - BOOST_CHECK_EQUAL(*cprops_[prop::response_information], response_information); - BOOST_CHECK_EQUAL(*cprops_[prop::server_reference], server_reference); - BOOST_CHECK_EQUAL(*cprops_[prop::authentication_method], authentication_method); - BOOST_CHECK_EQUAL(*cprops_[prop::authentication_data], authentication_data); + BOOST_TEST(session_present_ == session_present); + BOOST_TEST(reason_code_ == reason_code); + + cprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*cprops_[prop::session_expiry_interval] == session_expiry_interval); + BOOST_TEST(*cprops_[prop::receive_maximum] == receive_maximum); + BOOST_TEST(*cprops_[prop::maximum_qos] == max_qos); + BOOST_TEST(*cprops_[prop::retain_available] == retain_available); + BOOST_TEST(*cprops_[prop::maximum_packet_size] == maximum_packet_sz); + BOOST_TEST(*cprops_[prop::assigned_client_identifier] == assigned_client_id); + BOOST_TEST(*cprops_[prop::topic_alias_maximum] == topic_alias_max); + BOOST_TEST(*cprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(cprops_[prop::user_property].size() == 1); + BOOST_TEST(cprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(cprops_[prop::user_property][0].second == user_property_2); + BOOST_TEST(*cprops_[prop::wildcard_subscription_available] == wildcard_sub); + BOOST_TEST(*cprops_[prop::subscription_identifier_available] == sub_id); + BOOST_TEST(*cprops_[prop::shared_subscription_available] == shared_sub); + BOOST_TEST(*cprops_[prop::server_keep_alive] == server_keep_alive); + BOOST_TEST(*cprops_[prop::response_information] == response_information); + BOOST_TEST(*cprops_[prop::server_reference] == server_reference); + BOOST_TEST(*cprops_[prop::authentication_method] == authentication_method); + BOOST_TEST(*cprops_[prop::authentication_data] == authentication_data); } BOOST_AUTO_TEST_CASE(test_publish) { @@ -243,30 +243,30 @@ BOOST_AUTO_TEST_CASE(test_publish) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_publish(control_byte, remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [topic_, packet_id_, flags, pprops_, payload_] = *rv; - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); - BOOST_CHECK_EQUAL(topic_, topic); - BOOST_CHECK_EQUAL(payload_, payload); - - pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*pprops_[prop::payload_format_indicator], payload_format_indicator); - BOOST_CHECK_EQUAL(*pprops_[prop::message_expiry_interval], message_expiry_interval); - BOOST_CHECK_EQUAL(*pprops_[prop::topic_alias], topic_alias); - BOOST_CHECK_EQUAL(*pprops_[prop::response_topic], response_topic); - BOOST_CHECK_EQUAL(*pprops_[prop::correlation_data], correlation_data); - BOOST_ASSERT(pprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].first, publish_prop_1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].second, publish_prop_2); - BOOST_ASSERT(pprops_[prop::subscription_identifier].size() == 1); - BOOST_CHECK_EQUAL(pprops_[prop::subscription_identifier][0], subscription_identifier); - BOOST_CHECK_EQUAL(*pprops_[prop::content_type], content_type); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); + BOOST_TEST(topic_ == topic); + BOOST_TEST(payload_ == payload); + + pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*pprops_[prop::payload_format_indicator] == payload_format_indicator); + BOOST_TEST(*pprops_[prop::message_expiry_interval] == message_expiry_interval); + BOOST_TEST(*pprops_[prop::topic_alias] == topic_alias); + BOOST_TEST(*pprops_[prop::response_topic] == response_topic); + BOOST_TEST(*pprops_[prop::correlation_data] == correlation_data); + BOOST_TEST_REQUIRE(pprops_[prop::user_property].size() == 1); + BOOST_TEST(pprops_[prop::user_property][0].first == publish_prop_1); + BOOST_TEST(pprops_[prop::user_property][0].second == publish_prop_2); + BOOST_TEST_REQUIRE(pprops_[prop::subscription_identifier].size() == 1); + BOOST_TEST(pprops_[prop::subscription_identifier][0] == subscription_identifier); + BOOST_TEST(*pprops_[prop::content_type] == content_type); } BOOST_AUTO_TEST_CASE(test_large_publish) { @@ -283,17 +283,17 @@ BOOST_AUTO_TEST_CASE(test_large_publish) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_publish(control_byte, remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [topic_, packet_id_, flags, pprops, payload_] = *rv; - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); - BOOST_CHECK_EQUAL(topic_, topic); - BOOST_CHECK_EQUAL(payload_, large_payload); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); + BOOST_TEST(topic_ == topic); + BOOST_TEST(payload_ == large_payload); } BOOST_AUTO_TEST_CASE(test_puback) { @@ -313,23 +313,23 @@ BOOST_AUTO_TEST_CASE(test_puback) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_puback(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, pprops_] = *rv; - pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(reason_code_, reason_code); - BOOST_CHECK_EQUAL(*pprops_[prop::reason_string], reason_string); - BOOST_ASSERT(pprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].second, user_property_2); + pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(reason_code_ == reason_code); + BOOST_TEST(*pprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(pprops_[prop::user_property].size() == 1); + BOOST_TEST(pprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(pprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_pubrec) { @@ -349,23 +349,23 @@ BOOST_AUTO_TEST_CASE(test_pubrec) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_pubrec(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, pprops_] = *rv; - pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(reason_code_, reason_code); - BOOST_CHECK_EQUAL(*pprops_[prop::reason_string], reason_string); - BOOST_ASSERT(pprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].second, user_property_2); + pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(reason_code_ == reason_code); + BOOST_TEST(*pprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(pprops_[prop::user_property].size() == 1); + BOOST_TEST(pprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(pprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_pubrel) { @@ -385,23 +385,23 @@ BOOST_AUTO_TEST_CASE(test_pubrel) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_pubrel(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, pprops_] = *rv; - pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(reason_code_, reason_code); - BOOST_CHECK_EQUAL(*pprops_[prop::reason_string], reason_string); - BOOST_ASSERT(pprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].second, user_property_2); + pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(reason_code_ == reason_code); + BOOST_TEST(*pprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(pprops_[prop::user_property].size() == 1); + BOOST_TEST(pprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(pprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_pubcomp) { @@ -421,23 +421,23 @@ BOOST_AUTO_TEST_CASE(test_pubcomp) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_pubcomp(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv);; + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, pprops_] = *rv; - pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(reason_code_, reason_code); - BOOST_CHECK_EQUAL(*pprops_[prop::reason_string], reason_string); - BOOST_ASSERT(pprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(pprops_[prop::user_property][0].second, user_property_2); + pprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(reason_code_ == reason_code); + BOOST_TEST(*pprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(pprops_[prop::user_property].size() == 1); + BOOST_TEST(pprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(pprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_subscribe) { @@ -467,31 +467,31 @@ BOOST_AUTO_TEST_CASE(test_subscribe) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); auto rv = decoders::decode_subscribe(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [sprops_, filters_] = *rv; const auto& filter_ = filters_[0]; - BOOST_CHECK_EQUAL(std::get<0>(filter_), filters[0].topic_filter); + BOOST_TEST(std::get<0>(filter_) == filters[0].topic_filter); uint8_t options_ = std::get<1>(filter_); uint8_t mask = (static_cast(retain_handling) << 4) | (static_cast(retain_as_published) << 3) | (static_cast(no_local) << 2) | static_cast(qos); - BOOST_CHECK_EQUAL(options_, mask); + BOOST_TEST(options_ == mask); - sprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*sprops_[prop::subscription_identifier], sub_id); - BOOST_ASSERT(sprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(sprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(sprops_[prop::user_property][0].second, user_property_2); + sprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*sprops_[prop::subscription_identifier] == sub_id); + BOOST_TEST_REQUIRE(sprops_[prop::user_property].size() == 1); + BOOST_TEST(sprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(sprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_suback) { @@ -511,23 +511,23 @@ BOOST_AUTO_TEST_CASE(test_suback) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); auto rv = decoders::decode_suback(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [sprops_, reason_codes_] = *rv; - BOOST_CHECK(reason_codes_ == reason_codes); + BOOST_TEST(reason_codes_ == reason_codes); - sprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*sprops_[prop::reason_string], reason_string); - BOOST_ASSERT(sprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(sprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(sprops_[prop::user_property][0].second, user_property_2); + sprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*sprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(sprops_[prop::user_property].size() == 1); + BOOST_TEST(sprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(sprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_unsubscribe) { @@ -545,22 +545,22 @@ BOOST_AUTO_TEST_CASE(test_unsubscribe) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); auto rv = decoders::decode_unsubscribe(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [uprops_, topics_] = *rv; - BOOST_CHECK(topics_ == topics); + BOOST_TEST(topics_ == topics); - uprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_ASSERT(uprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(uprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(uprops_[prop::user_property][0].second, user_property_2); + uprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST_REQUIRE(uprops_[prop::user_property].size() == 1); + BOOST_TEST(uprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(uprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_unsuback) { @@ -580,23 +580,23 @@ BOOST_AUTO_TEST_CASE(test_unsuback) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto packet_id_ = decoders::decode_packet_id(it); - BOOST_CHECK(packet_id); - BOOST_CHECK_EQUAL(*packet_id_, packet_id); + BOOST_TEST_REQUIRE(packet_id_.has_value()); + BOOST_TEST(*packet_id_ == packet_id); auto rv = decoders::decode_unsuback(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [uprops_, reason_codes_] = *rv; - BOOST_CHECK(reason_codes_ == reason_codes); + BOOST_TEST(reason_codes_ == reason_codes); - uprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*uprops_[prop::reason_string], reason_string); - BOOST_ASSERT(uprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(uprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(uprops_[prop::user_property][0].second, user_property_2); + uprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*uprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(uprops_[prop::user_property].size() == 1); + BOOST_TEST(uprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(uprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_disconnect) { @@ -619,22 +619,22 @@ BOOST_AUTO_TEST_CASE(test_disconnect) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_disconnect(remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, dprops_] = *rv; - BOOST_CHECK_EQUAL(reason_code_, reason_code); - - dprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*dprops_[prop::session_expiry_interval], session_expiry_interval); - BOOST_CHECK_EQUAL(*dprops_[prop::reason_string], reason_string); - BOOST_ASSERT(dprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(dprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(dprops_[prop::user_property][0].second, user_property_2); - BOOST_CHECK_EQUAL(*dprops_[prop::server_reference], server_reference); + BOOST_TEST(reason_code_ == reason_code); + + dprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*dprops_[prop::session_expiry_interval] == session_expiry_interval); + BOOST_TEST(*dprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(dprops_[prop::user_property].size() == 1); + BOOST_TEST(dprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(dprops_[prop::user_property][0].second == user_property_2); + BOOST_TEST(*dprops_[prop::server_reference] == server_reference); } BOOST_AUTO_TEST_CASE(test_auth) { @@ -658,56 +658,55 @@ BOOST_AUTO_TEST_CASE(test_auth) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_auth(remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, aprops_] = *rv; - BOOST_CHECK_EQUAL(reason_code_, reason_code); - - aprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_ASSERT(p); return true; }); - BOOST_CHECK_EQUAL(*aprops_[prop::authentication_method], authentication_method); - BOOST_CHECK_EQUAL(*aprops_[prop::authentication_data], authentication_data); - BOOST_CHECK_EQUAL(*aprops_[prop::reason_string], reason_string); - BOOST_ASSERT(aprops_[prop::user_property].size() == 1); - BOOST_CHECK_EQUAL(aprops_[prop::user_property][0].first, user_property_1); - BOOST_CHECK_EQUAL(aprops_[prop::user_property][0].second, user_property_2); + BOOST_TEST(reason_code_ == reason_code); + + aprops_.visit([](const auto& p, const auto&) { (void)p; BOOST_TEST_REQUIRE(p); return true; }); + BOOST_TEST(*aprops_[prop::authentication_method] == authentication_method); + BOOST_TEST(*aprops_[prop::authentication_data] == authentication_data); + BOOST_TEST(*aprops_[prop::reason_string] == reason_string); + BOOST_TEST_REQUIRE(aprops_[prop::user_property].size() == 1); + BOOST_TEST(aprops_[prop::user_property][0].first == user_property_1); + BOOST_TEST(aprops_[prop::user_property][0].second == user_property_2); } BOOST_AUTO_TEST_CASE(test_pingreq) { auto msg = encoders::encode_pingreq(); auto encoded_pingreq = std::string({ -64 /* 192 */, 0 }); - BOOST_CHECK_EQUAL(msg, encoded_pingreq); + BOOST_TEST(msg == encoded_pingreq); } BOOST_AUTO_TEST_CASE(test_pingresp) { auto msg = encoders::encode_pingresp(); auto encoded_pingresp = std::string({ -48 /* 208 */, 0 }); - BOOST_CHECK_EQUAL(msg, encoded_pingresp); + BOOST_TEST(msg == encoded_pingresp); } BOOST_AUTO_TEST_CASE(subscription_identifiers) { // check boost::container::small_vector interface - BOOST_ASSERT(is_small_vector); + BOOST_TEST_REQUIRE(is_small_vector); // check optional interface prop::subscription_identifiers sub_ids; sub_ids.emplace(40); - BOOST_CHECK(sub_ids); - BOOST_CHECK(sub_ids.has_value()); - BOOST_CHECK_EQUAL(*sub_ids, 40); + BOOST_TEST_REQUIRE(sub_ids.has_value()); + BOOST_TEST(*sub_ids == 40); *sub_ids = 41; - BOOST_CHECK_EQUAL(sub_ids.value(), 41); - BOOST_CHECK_EQUAL(sub_ids.value_or(-1), 41); + BOOST_TEST(sub_ids.value() == 41); + BOOST_TEST(sub_ids.value_or(-1) == 41); sub_ids.reset(); - BOOST_CHECK(!sub_ids); - BOOST_CHECK_EQUAL(sub_ids.value_or(-1), -1); + BOOST_TEST(!sub_ids); + BOOST_TEST(sub_ids.value_or(-1) == -1); sub_ids.emplace(); - BOOST_CHECK_EQUAL(*sub_ids, 0); + BOOST_TEST(*sub_ids == 0); } BOOST_AUTO_TEST_CASE(empty_user_property) { @@ -722,18 +721,18 @@ BOOST_AUTO_TEST_CASE(empty_user_property) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_publish(control_byte, remain_length, it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [topic_, packet_id_, flags, pprops_, payload_] = *rv; auto user_props_ = pprops_[prop::user_property]; - BOOST_ASSERT(user_props_.size() == 1); - BOOST_CHECK_EQUAL(user_props_[0].first, ""); - BOOST_CHECK_EQUAL(user_props_[0].second, ""); + BOOST_TEST_REQUIRE(user_props_.size() == 1); + BOOST_TEST(user_props_[0].first == ""); + BOOST_TEST(user_props_[0].second == ""); } BOOST_AUTO_TEST_CASE(deserialize_user_property) { @@ -745,18 +744,18 @@ BOOST_AUTO_TEST_CASE(deserialize_user_property) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_ASSERT(packet_id_); + BOOST_TEST_REQUIRE(packet_id_.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_puback(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, pprops_] = *rv; auto user_props_ = pprops_[prop::user_property]; - BOOST_ASSERT(user_props_.size() == 1); - BOOST_CHECK_EQUAL(user_props_[0].first, "key"); - BOOST_CHECK_EQUAL(user_props_[0].second, "val"); + BOOST_TEST_REQUIRE(user_props_.size() == 1); + BOOST_TEST(user_props_[0].first == "key"); + BOOST_TEST(user_props_[0].second == "val"); } BOOST_AUTO_TEST_CASE(deserialize_empty_user_property) { @@ -764,22 +763,22 @@ BOOST_AUTO_TEST_CASE(deserialize_empty_user_property) { const char puback[] = { 64, 9, 0, 1, 0, 5, 38, 0, 0, 0, 0 }; - std::string msg{ puback, sizeof(puback) / sizeof(char) }; + std::string msg { puback, sizeof(puback) / sizeof(char) }; byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_ASSERT(packet_id_); + BOOST_TEST_REQUIRE(packet_id_.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_puback(remain_length - sizeof(uint16_t), it); - BOOST_ASSERT(rv); + BOOST_TEST_REQUIRE(rv.has_value()); const auto& [reason_code_, pprops_] = *rv; auto user_props_ = pprops_[prop::user_property]; - BOOST_ASSERT(user_props_.size() == 1); - BOOST_CHECK_EQUAL(user_props_[0].first, ""); - BOOST_CHECK_EQUAL(user_props_[0].second, ""); + BOOST_TEST_REQUIRE(user_props_.size() == 1); + BOOST_TEST(user_props_[0].first == ""); + BOOST_TEST(user_props_[0].second == ""); } BOOST_AUTO_TEST_CASE(malformed_user_property) { @@ -791,12 +790,12 @@ BOOST_AUTO_TEST_CASE(malformed_user_property) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_ASSERT(packet_id_); + BOOST_TEST_REQUIRE(packet_id_.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_puback(remain_length - sizeof(uint16_t), it); - BOOST_CHECK(!rv); + BOOST_TEST(!rv); } BOOST_AUTO_TEST_CASE(malformed_reason_string) { @@ -808,12 +807,12 @@ BOOST_AUTO_TEST_CASE(malformed_reason_string) { byte_citer it = msg.cbegin(), last = msg.cend(); auto header = decoders::decode_fixed_header(it, last); - BOOST_ASSERT(header); + BOOST_TEST_REQUIRE(header.has_value()); auto packet_id_ = decoders::decode_packet_id(it); - BOOST_ASSERT(packet_id_); + BOOST_TEST_REQUIRE(packet_id_.has_value()); const auto& [control_byte, remain_length] = *header; auto rv = decoders::decode_puback(remain_length - sizeof(uint16_t), it); - BOOST_CHECK(!rv); + BOOST_TEST(!rv); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/session.cpp b/test/unit/session.cpp index f08ba50..609e6c8 100644 --- a/test/unit/session.cpp +++ b/test/unit/session.cpp @@ -25,17 +25,17 @@ BOOST_AUTO_TEST_SUITE(session/*, *boost::unit_test::disabled()*/) BOOST_AUTO_TEST_CASE(session_state_session_present) { detail::session_state session_state; - BOOST_CHECK_EQUAL(session_state.session_present(), false); + BOOST_TEST(session_state.session_present() == false); session_state.session_present(true); - BOOST_CHECK_EQUAL(session_state.session_present(), true); + BOOST_TEST(session_state.session_present() == true); session_state.session_present(false); - BOOST_CHECK_EQUAL(session_state.session_present(), false); + BOOST_TEST(session_state.session_present() == false); - BOOST_CHECK_EQUAL(session_state.subscriptions_present(), false); + BOOST_TEST(session_state.subscriptions_present() == false); session_state.subscriptions_present(true); - BOOST_CHECK_EQUAL(session_state.subscriptions_present(), true); + BOOST_TEST(session_state.subscriptions_present() == true); session_state.subscriptions_present(false); - BOOST_CHECK_EQUAL(session_state.subscriptions_present(), false); + BOOST_TEST(session_state.subscriptions_present() == false); } BOOST_AUTO_TEST_CASE(clear_waiting_on_pubrel) { @@ -54,10 +54,10 @@ BOOST_AUTO_TEST_CASE(clear_waiting_on_pubrel) { asio::steady_timer timer(ioc.get_executor()); timer.expires_after(std::chrono::milliseconds(50)); timer.async_wait([&svc_ptr](error_code) { - BOOST_CHECK_EQUAL(svc_ptr.use_count(), 2); + BOOST_TEST(svc_ptr.use_count() == 2); svc_ptr->update_session_state(); // session_present = false // publish_rec_op should complete - BOOST_CHECK_EQUAL(svc_ptr.use_count(), 1); + BOOST_TEST(svc_ptr.use_count() == 1); }); ioc.run(); diff --git a/test/unit/subscribe_op.cpp b/test/unit/subscribe_op.cpp index 44a182d..e8046df 100644 --- a/test/unit/subscribe_op.cpp +++ b/test/unit/subscribe_op.cpp @@ -35,9 +35,9 @@ BOOST_AUTO_TEST_CASE(pid_overrun) { auto handler = [&handlers_called](error_code ec, std::vector rcs, suback_props) { ++handlers_called; - BOOST_CHECK(ec == client::error::pid_overrun); - BOOST_ASSERT(rcs.size() == 1); - BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty); + BOOST_TEST(ec == client::error::pid_overrun); + BOOST_TEST_REQUIRE(rcs.size() == 1); + BOOST_TEST(rcs[0] == reason_codes::empty); }; detail::subscribe_op< @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(pid_overrun) { ); ioc.run_for(std::chrono::milliseconds(500)); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); + BOOST_TEST(handlers_called == expected_handlers_called); } void run_test( @@ -66,11 +66,11 @@ void run_test( (error_code ec, std::vector rcs, suback_props) { ++handlers_called; - BOOST_CHECK(ec == expected_ec); - BOOST_ASSERT(rcs.size() == num_tp); + BOOST_TEST(ec == expected_ec); + BOOST_TEST_REQUIRE(rcs.size() == num_tp); for (size_t i = 0; i < rcs.size(); ++i) - BOOST_CHECK_EQUAL(rcs[i], reason_codes::empty); + BOOST_TEST(rcs[i] == reason_codes::empty); }; detail::subscribe_op< @@ -79,7 +79,7 @@ void run_test( .perform(topics, sprops); ioc.run_for(std::chrono::milliseconds(500)); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); + BOOST_TEST(handlers_called == expected_handlers_called); } void run_test( diff --git a/test/unit/traits.cpp b/test/unit/traits.cpp index 789e4a5..80dfc73 100644 --- a/test/unit/traits.cpp +++ b/test/unit/traits.cpp @@ -8,8 +8,9 @@ #include #include -#include +#include +#include #include #include #include @@ -36,7 +37,7 @@ struct good_authenticator { CompletionToken&& token ) { using error_code = boost::system::error_code; - using Signature = void(error_code, std::string); + using Signature = void (error_code, std::string); auto initiate = [](auto, auth_step_e, std::string) {}; @@ -60,10 +61,9 @@ struct bad_authenticator { } }; -BOOST_AUTO_TEST_CASE(is_authenticator) { - BOOST_STATIC_ASSERT(detail::is_authenticator); - BOOST_STATIC_ASSERT(!detail::is_authenticator); -} + +BOOST_STATIC_ASSERT(detail::is_authenticator); +BOOST_STATIC_ASSERT(!detail::is_authenticator); namespace asio = boost::asio; namespace beast = boost::beast; @@ -73,32 +73,27 @@ using tls_layer = asio::ssl::stream; using websocket_tcp_layer = beast::websocket::stream; using websocket_tls_layer = beast::websocket::stream; -BOOST_AUTO_TEST_CASE(has_next_layer) { - BOOST_STATIC_ASSERT(!detail::has_next_layer); - BOOST_STATIC_ASSERT(detail::has_next_layer); - BOOST_STATIC_ASSERT(detail::has_next_layer); - BOOST_STATIC_ASSERT(detail::has_next_layer); -} - -BOOST_AUTO_TEST_CASE(has_tls_layer) { - BOOST_STATIC_ASSERT(!detail::has_tls_layer); - BOOST_STATIC_ASSERT(detail::has_tls_layer); - BOOST_STATIC_ASSERT(!detail::has_tls_layer); - BOOST_STATIC_ASSERT(detail::has_tls_layer); -} - -BOOST_AUTO_TEST_CASE(has_tls_handshake) { - BOOST_STATIC_ASSERT(!detail::has_tls_handshake); - BOOST_STATIC_ASSERT(detail::has_tls_handshake); - BOOST_STATIC_ASSERT(!detail::has_tls_handshake); - BOOST_STATIC_ASSERT(!detail::has_tls_handshake); -} - -BOOST_AUTO_TEST_CASE(has_ws_handskae) { - BOOST_STATIC_ASSERT(!detail::has_ws_handshake); - BOOST_STATIC_ASSERT(!detail::has_ws_handshake); - BOOST_STATIC_ASSERT(detail::has_ws_handshake); - BOOST_STATIC_ASSERT(detail::has_ws_handshake); -} + +BOOST_STATIC_ASSERT(!detail::has_next_layer); +BOOST_STATIC_ASSERT(detail::has_next_layer); +BOOST_STATIC_ASSERT(detail::has_next_layer); +BOOST_STATIC_ASSERT(detail::has_next_layer); + + +BOOST_STATIC_ASSERT(!detail::has_tls_layer); +BOOST_STATIC_ASSERT(detail::has_tls_layer); +BOOST_STATIC_ASSERT(!detail::has_tls_layer); +BOOST_STATIC_ASSERT(detail::has_tls_layer); + +BOOST_STATIC_ASSERT(!detail::has_tls_handshake); +BOOST_STATIC_ASSERT(detail::has_tls_handshake); +BOOST_STATIC_ASSERT(!detail::has_tls_handshake); +BOOST_STATIC_ASSERT(!detail::has_tls_handshake); + + +BOOST_STATIC_ASSERT(!detail::has_ws_handshake); +BOOST_STATIC_ASSERT(!detail::has_ws_handshake); +BOOST_STATIC_ASSERT(detail::has_ws_handshake); +BOOST_STATIC_ASSERT(detail::has_ws_handshake); BOOST_AUTO_TEST_SUITE_END(); diff --git a/test/unit/unsubscribe_op.cpp b/test/unit/unsubscribe_op.cpp index 21241c3..059c69c 100644 --- a/test/unit/unsubscribe_op.cpp +++ b/test/unit/unsubscribe_op.cpp @@ -35,9 +35,9 @@ BOOST_AUTO_TEST_CASE(pid_overrun) { auto handler = [&handlers_called](error_code ec, std::vector rcs, unsuback_props) { ++handlers_called; - BOOST_CHECK(ec == client::error::pid_overrun); - BOOST_ASSERT(rcs.size() == 1); - BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty); + BOOST_TEST(ec == client::error::pid_overrun); + BOOST_TEST_REQUIRE(rcs.size() == 1); + BOOST_TEST(rcs[0] == reason_codes::empty); }; detail::unsubscribe_op< @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(pid_overrun) { .perform({ "topic" }, unsubscribe_props {}); ioc.run_for(std::chrono::milliseconds(500)); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); + BOOST_TEST(handlers_called == expected_handlers_called); } void run_test( @@ -64,11 +64,11 @@ void run_test( (error_code ec, std::vector rcs, unsuback_props) { ++handlers_called; - BOOST_CHECK(ec == expected_ec); - BOOST_ASSERT(rcs.size() == num_tp); + BOOST_TEST(ec == expected_ec); + BOOST_TEST_REQUIRE(rcs.size() == num_tp); for (size_t i = 0; i < rcs.size(); ++i) - BOOST_CHECK_EQUAL(rcs[i], reason_codes::empty); + BOOST_TEST(rcs[i] == reason_codes::empty); }; detail::unsubscribe_op< @@ -77,7 +77,7 @@ void run_test( .perform(topics, uprops); ioc.run_for(std::chrono::milliseconds(500)); - BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called); + BOOST_TEST(handlers_called == expected_handlers_called); } void run_test(