forked from boostorg/mqtt5
(Un)subscribe validates the number of topics and reason codes
Test Plan: related to T12015 - (un)subscribe reason codes will always contain as many reason codes as there are topic filters - if, by some odd chance, the client receives the wrong number of rcs or some are invalid, it will treat it as malformed - both subscribe_op and unsubscribe_op should be 100% covered by tests now Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D27592
This commit is contained in:
@@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(pid_overrun) {
|
||||
}
|
||||
|
||||
void run_test(
|
||||
error_code expected_ec, const std::string& topic_filter,
|
||||
error_code expected_ec, const std::vector<std::string>& topics,
|
||||
const unsubscribe_props& uprops = {}, const connack_props& cprops = {}
|
||||
) {
|
||||
constexpr int expected_handlers_called = 1;
|
||||
@@ -45,24 +45,35 @@ void run_test(
|
||||
using client_service_type = test::test_service<asio::ip::tcp::socket>;
|
||||
auto svc_ptr = std::make_shared<client_service_type>(ioc.get_executor(), cprops);
|
||||
|
||||
auto handler = [&handlers_called, expected_ec]
|
||||
auto handler = [&handlers_called, expected_ec, num_tp = topics.size()]
|
||||
(error_code ec, std::vector<reason_code> rcs, unsuback_props) {
|
||||
++handlers_called;
|
||||
|
||||
BOOST_CHECK(ec == expected_ec);
|
||||
BOOST_ASSERT(rcs.size() == 1);
|
||||
BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty);
|
||||
BOOST_ASSERT(rcs.size() == num_tp);
|
||||
|
||||
for (size_t i = 0; i < rcs.size(); ++i)
|
||||
BOOST_CHECK_EQUAL(rcs[i], reason_codes::empty);
|
||||
};
|
||||
|
||||
detail::unsubscribe_op<
|
||||
client_service_type, decltype(handler)
|
||||
> { svc_ptr, std::move(handler) }
|
||||
.perform({ topic_filter }, uprops);
|
||||
.perform(topics, uprops);
|
||||
|
||||
ioc.run_for(std::chrono::milliseconds(500));
|
||||
BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called);
|
||||
}
|
||||
|
||||
void run_test(
|
||||
error_code expected_ec, const std::string& topic,
|
||||
const unsubscribe_props& uprops = {}, const connack_props& cprops = {}
|
||||
) {
|
||||
return run_test(
|
||||
expected_ec, std::vector<std::string> { topic }, uprops, cprops
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(invalid_topic_filter_1) {
|
||||
run_test(client::error::invalid_topic, "");
|
||||
}
|
||||
@@ -111,4 +122,8 @@ BOOST_AUTO_TEST_CASE(packet_too_large) {
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(zero_topic_filters) {
|
||||
run_test(client::error::invalid_topic, std::vector<std::string> {});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user