Skip to content

Commit

Permalink
Added test.
Browse files Browse the repository at this point in the history
  • Loading branch information
redboltz committed Sep 4, 2019
1 parent 88e3374 commit e8ce64d
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions test/sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,102 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single ) {
do_combi_test_sync(test);
}

BOOST_AUTO_TEST_CASE( sub_v5_options ) {
auto test = [](boost::asio::io_service& ios, auto& c, auto& s, auto& /*b*/) {
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
c->set_clean_session(true);


checker chk = {
// connect
cont("h_connack"),
// subscribe topic1
cont("h_suback"),
// unsubscribe topic1
cont("h_unsuback"),
// disconnect
cont("h_close"),
};

switch (c->get_protocol_version()) {
case MQTT_NS::protocol_version::v3_1_1:
c->set_connack_handler(
[&chk, &c]
(bool sp, std::uint8_t connack_return_code) {
MQTT_CHK("h_connack");
BOOST_TEST(sp == false);
BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted);
c->subscribe("topic1", MQTT_NS::qos::at_most_once);
return true;
});
c->set_suback_handler(
[&chk, &c]
(packet_id_t /*packet_id*/, std::vector<MQTT_NS::optional<std::uint8_t>> /*results*/) {
MQTT_CHK("h_suback");
c->unsubscribe("topic1");
return true;
});
c->set_unsuback_handler(
[&chk, &c]
(packet_id_t /*packet_id*/) {
MQTT_CHK("h_unsuback");
c->disconnect();
return true;
});
break;
case MQTT_NS::protocol_version::v5:
c->set_v5_connack_handler(
[&chk, &c]
(bool sp, std::uint8_t connack_return_code, std::vector<MQTT_NS::v5::property_variant> /*props*/) {
MQTT_CHK("h_connack");
BOOST_TEST(sp == false);
BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted);
std::uint8_t option = 0;
MQTT_NS::subscribe::set_qos(option, MQTT_NS::qos::at_most_once);
MQTT_NS::subscribe::set_no_local(option, true);
MQTT_NS::subscribe::set_retain_as_published(option, true);
MQTT_NS::subscribe::set_retain_handling(option, 2);
c->subscribe("topic1", MQTT_NS::qos::at_most_once);
return true;
});
c->set_v5_suback_handler(
[&chk, &c]
(packet_id_t /*packet_id*/, std::vector<std::uint8_t> /*reasons*/, std::vector<MQTT_NS::v5::property_variant> /*props*/) {
MQTT_CHK("h_suback");
c->unsubscribe("topic1");
return true;
});
c->set_v5_unsuback_handler(
[&chk, &c]
(packet_id_t /*packet_id*/, std::vector<std::uint8_t> /*reasons*/, std::vector<MQTT_NS::v5::property_variant> /*props*/) {
MQTT_CHK("h_unsuback");
c->disconnect();
return true;
});
break;
default:
BOOST_CHECK(false);
break;
}

c->set_close_handler(
[&chk, &s]
() {
MQTT_CHK("h_close");
s.close();
});
c->set_error_handler(
[]
(boost::system::error_code const&) {
BOOST_CHECK(false);
});
c->connect();
ios.run();
BOOST_TEST(chk.all());
};
do_combi_test_sync(test);
}

BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg ) {
auto test = [](boost::asio::io_service& ios, auto& c, auto& s, auto& /*b*/) {
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
Expand Down

0 comments on commit e8ce64d

Please sign in to comment.