Files

67 lines
2.1 KiB
C++
Raw Permalink Normal View History

2024-05-27 10:35:06 +02:00
//
2025-02-14 13:42:23 +01:00
// Copyright (c) 2023-2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic
2024-05-27 10:35:06 +02:00
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
//
2025-01-13 16:11:41 +01:00
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/mqtt5.hpp>
#include <boost/test/unit_test.hpp>
2024-10-08 09:59:35 +02:00
#include <chrono>
2025-01-13 16:11:41 +01:00
#include <cstdint>
2024-10-08 09:59:35 +02:00
#include <string>
2025-01-13 16:11:41 +01:00
#include "test_common/test_service.hpp"
2024-10-08 09:59:35 +02:00
2025-01-13 16:11:41 +01:00
using namespace boost::mqtt5;
BOOST_AUTO_TEST_SUITE(session/*, *boost::unit_test::disabled()*/)
BOOST_AUTO_TEST_CASE(session_state_session_present) {
2025-01-13 16:11:41 +01:00
detail::session_state session_state;
2025-01-13 16:11:41 +01:00
BOOST_TEST(session_state.session_present() == false);
session_state.session_present(true);
BOOST_TEST(session_state.session_present() == true);
session_state.session_present(false);
BOOST_TEST(session_state.session_present() == false);
2025-01-13 16:11:41 +01:00
BOOST_TEST(session_state.subscriptions_present() == false);
session_state.subscriptions_present(true);
BOOST_TEST(session_state.subscriptions_present() == true);
session_state.subscriptions_present(false);
BOOST_TEST(session_state.subscriptions_present() == false);
}
BOOST_AUTO_TEST_CASE(clear_waiting_on_pubrel) {
2025-01-13 16:11:41 +01:00
asio::io_context ioc;
using client_service_type = test::test_service<asio::ip::tcp::socket>;
auto svc_ptr = std::make_shared<client_service_type>(ioc.get_executor());
svc_ptr->open_stream();
2025-01-13 16:11:41 +01:00
decoders::publish_message pub_msg = std::make_tuple(
"topic", uint16_t(1), uint8_t(0b0100), publish_props {}, "payload"
);
2025-01-13 16:11:41 +01:00
detail::publish_rec_op<client_service_type> { svc_ptr }.perform(pub_msg);
2025-01-13 16:11:41 +01:00
// let publish_rec_op reach wait_on_pubrel stage
asio::steady_timer timer(ioc.get_executor());
timer.expires_after(std::chrono::milliseconds(50));
timer.async_wait([&svc_ptr](error_code) {
BOOST_TEST(svc_ptr.use_count() == 2);
svc_ptr->update_session_state(); // session_present = false
// publish_rec_op should complete
BOOST_TEST(svc_ptr.use_count() == 1);
});
2025-01-13 16:11:41 +01:00
ioc.run();
}
BOOST_AUTO_TEST_SUITE_END();