Skip to content

Commit 0e62d8f

Browse files
committed
Consistently use BOOST_TEST instead of BOOST_CHECK in tests
Summary: related to T13767 We used BOOST_CHECK in older tests and BOOST_TEST macro in newer tests. Now we use BOOST_TEST consistently. Reviewers: ivica! Subscribers: iljazovic, miljen Differential Revision: https://repo.mireo.local/D31701
1 parent 4cbae10 commit 0e62d8f

16 files changed

+317
-379
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Using the library
4343

4444
1. Download [Boost](https://www.boost.org/users/download/), and add it to your include path.
4545
2. If you use SSL, download [OpenSSL](https://www.openssl.org/), link the library and add it to your include path.
46-
3. Additionally, you can add Async.MQTT5's `include` folder to your include path.
46+
3. Add Async.MQTT5's `include` folder to your include path.
4747

4848
You can compile the example below with the following command line on Linux:
4949

example/hello_world_over_websocket_tls.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,10 @@
1414
#include <boost/asio/ip/tcp.hpp>
1515

1616
#include <boost/beast/websocket.hpp>
17+
#include <boost/beast/ssl/ssl_stream.hpp> // async_teardown specialization for websocket ssl stream
1718

1819
#include <async_mqtt5.hpp>
1920

20-
namespace boost::beast::websocket {
21-
22-
// boost::beast::websocket::async_teardown is a free function designed to initiate the asynchronous teardown of a connection.
23-
// The specific behaviour of this function is based on the NextLayer type (Socket type) used to create the ``__WEBSOCKET_STREAM__``.
24-
// ``__Beast__`` library includes an implementation of this function for ``__TCP_SOCKET__``.
25-
// However, the callers are responsible for providing a suitable overload of this function for any other type,
26-
// such as ``__SSL_STREAM__`` as shown in this example.
27-
// See ``__BEAST_ASYNC_TEARDOWN__`` for more information.
28-
template <typename TeardownHandler>
29-
void async_teardown(
30-
boost::beast::role_type role,
31-
asio::ssl::stream<asio::ip::tcp::socket>& stream,
32-
TeardownHandler&& handler
33-
) {
34-
return stream.async_shutdown(std::forward<TeardownHandler>(handler));
35-
}
36-
37-
} // end namespace boost::beast::websocket
38-
39-
4021
// External customization point.
4122
namespace async_mqtt5 {
4223

@@ -51,7 +32,7 @@ struct tls_handshake_type<boost::asio::ssl::stream<StreamBase>> {
5132
template <typename StreamBase>
5233
void assign_tls_sni(
5334
const authority_path& ap,
54-
boost::asio::ssl::context& ctx,
35+
boost::asio::ssl::context& /*ctx*/,
5536
boost::asio::ssl::stream<StreamBase>& stream
5637
) {
5738
SSL_set_tlsext_host_name(stream.native_handle(), ap.host.c_str());

test/include/test_common/protocol_logging.hpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/include/test_common/test_broker.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#ifndef ASYNC_MQTT5_TEST_TEST_BROKER_HPP
99
#define ASYNC_MQTT5_TEST_TEST_BROKER_HPP
1010

11+
#include <boost/test/unit_test.hpp>
12+
#include <boost/test/tools/interface.hpp>
13+
14+
#include <algorithm>
15+
#include <cstdint>
16+
#include <deque>
1117
#include <memory>
1218
#include <numeric>
1319
#include <string>
@@ -17,18 +23,21 @@
1723

1824
#include <boost/asio/any_completion_handler.hpp>
1925
#include <boost/asio/any_io_executor.hpp>
26+
#include <boost/asio/async_result.hpp>
27+
#include <boost/asio/buffer.hpp>
2028
#include <boost/asio/cancellation_signal.hpp>
29+
#include <boost/asio/dispatch.hpp>
30+
#include <boost/asio/execution_context.hpp>
2131
#include <boost/asio/post.hpp>
2232
#include <boost/asio/prepend.hpp>
23-
2433
#include <boost/asio/ip/tcp.hpp>
34+
#include <boost/system/error_code.hpp>
2535

36+
#include <async_mqtt5/types.hpp>
2637
#include <async_mqtt5/impl/codecs/message_decoders.hpp>
2738

2839
#include "test_common/message_exchange.hpp"
2940
#include "test_common/packet_util.hpp"
30-
#include "test_common/protocol_logging.hpp"
31-
3241

3342
namespace async_mqtt5::test {
3443

@@ -157,16 +166,15 @@ class test_broker : public asio::execution_context::service {
157166
size_t buffers_size = std::distance(
158167
asio::buffer_sequence_begin(buffers), asio::buffer_sequence_end(buffers)
159168
);
160-
BOOST_CHECK_EQUAL(buffers_size, expected.size());
169+
BOOST_TEST(buffers_size == expected.size());
161170

162171
size_t num_packets = std::min(buffers_size, expected.size());
163172
auto it = asio::buffer_sequence_begin(buffers);
164173
for (size_t i = 0; i < num_packets; ++i, ++it) {
165-
BOOST_CHECK_EQUAL(it->size(), expected[i].size());
174+
BOOST_TEST(it->size() == expected[i].size());
166175
size_t len = std::min(it->size(), expected[i].size());
167176
if (memcmp(it->data(), expected[i].data(), len))
168-
BOOST_CHECK_MESSAGE(
169-
false,
177+
BOOST_TEST_MESSAGE(
170178
concat_strings(
171179
"Packet mismatch!\nExpected: ",
172180
to_readable_packet(expected[i]),
@@ -176,12 +184,9 @@ class test_broker : public asio::execution_context::service {
176184
);
177185
}
178186
} else
179-
BOOST_CHECK_MESSAGE(
180-
false,
181-
concat_strings(
182-
"Broker side did not expect: ",
183-
boost::algorithm::join(to_readable_packets(buffers), ",")
184-
)
187+
BOOST_TEST_MESSAGE(
188+
"Broker side did not expect: " <<
189+
boost::algorithm::join(to_readable_packets(buffers), ",")
185190
);
186191

187192
auto complete_op = reply_action ?

test/integration/async_sender.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <boost/asio/io_context.hpp>
1717
#include <boost/asio/steady_timer.hpp>
18+
#include <boost/asio/detached.hpp>
1819

1920
#include <async_mqtt5/mqtt_client.hpp>
2021
#include <async_mqtt5/types.hpp>

test/integration/client.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,12 @@
2020
#include <boost/asio/ssl.hpp>
2121

2222
#include <boost/beast/websocket.hpp>
23+
#include <boost/beast/ssl/ssl_stream.hpp> // async_teardown specialization for websocket ssl stream
2324

2425
#include <boost/system/error_code.hpp>
2526

2627
#include <async_mqtt5.hpp>
2728

28-
namespace boost::beast::websocket {
29-
30-
template <typename TeardownHandler>
31-
void async_teardown(
32-
boost::beast::role_type /* role */,
33-
asio::ssl::stream<asio::ip::tcp::socket>& stream,
34-
TeardownHandler&& handler
35-
) {
36-
return stream.async_shutdown(std::forward<TeardownHandler>(handler));
37-
}
38-
39-
} // end namespace boost::beast::websocket
40-
4129
namespace async_mqtt5 {
4230

4331
template <typename StreamBase>

test/integration/ping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void run_test(
8181
});
8282

8383
ioc.run();
84-
BOOST_CHECK(broker.received_all_expected());
84+
BOOST_TEST(broker.received_all_expected());
8585
}
8686

8787
BOOST_FIXTURE_TEST_CASE(ping_pong_client_ka, shared_test_data) {

test/integration/re_authentication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void run_test(
9999
});
100100

101101
ioc.run();
102-
BOOST_CHECK(broker.received_all_expected());
102+
BOOST_TEST(broker.received_all_expected());
103103
}
104104

105105
BOOST_FIXTURE_TEST_CASE(successful_re_auth, shared_test_data) {

test/integration/sub_unsub.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ void run_test(test::msg_exchange broker_side) {
9393
[&handlers_called, &c](error_code ec, std::vector<reason_code> rcs, suback_props) {
9494
++handlers_called;
9595

96-
BOOST_CHECK(!ec);
97-
BOOST_ASSERT(rcs.size() == 1);
98-
BOOST_CHECK_EQUAL(rcs[0], reason_codes::granted_qos_0);
96+
BOOST_TEST(!ec);
97+
BOOST_TEST_REQUIRE(rcs.size() == 1);
98+
BOOST_TEST(rcs[0] == reason_codes::granted_qos_0);
9999

100100
c.cancel();
101101
}
@@ -106,17 +106,17 @@ void run_test(test::msg_exchange broker_side) {
106106
[&handlers_called, &c](error_code ec, std::vector<reason_code> rcs, unsuback_props) {
107107
++handlers_called;
108108

109-
BOOST_CHECK(!ec);
110-
BOOST_ASSERT(rcs.size() == 1);
111-
BOOST_CHECK_EQUAL(rcs[0], reason_codes::success);
109+
BOOST_TEST(!ec);
110+
BOOST_TEST_REQUIRE(rcs.size() == 1);
111+
BOOST_TEST(rcs[0] == reason_codes::success);
112112

113113
c.cancel();
114114
}
115115
);
116116

117117
ioc.run_for(5s);
118-
BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called);
119-
BOOST_CHECK(broker.received_all_expected());
118+
BOOST_TEST(handlers_called == expected_handlers_called);
119+
BOOST_TEST(broker.received_all_expected());
120120
}
121121

122122
// subscribe
@@ -423,9 +423,9 @@ void run_cancellation_test(test::msg_exchange broker_side) {
423423
[&handlers_called, &c](error_code ec, std::vector<reason_code> rcs, suback_props) {
424424
++handlers_called;
425425

426-
BOOST_CHECK(ec == asio::error::operation_aborted);
427-
BOOST_ASSERT(rcs.size() == 1);
428-
BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty);
426+
BOOST_TEST(ec == asio::error::operation_aborted);
427+
BOOST_TEST_REQUIRE(rcs.size() == 1);
428+
BOOST_TEST(rcs[0] == reason_codes::empty);
429429

430430
c.cancel();
431431
}
@@ -439,9 +439,9 @@ void run_cancellation_test(test::msg_exchange broker_side) {
439439
[&handlers_called, &c](error_code ec, std::vector<reason_code> rcs, unsuback_props) {
440440
++handlers_called;
441441

442-
BOOST_CHECK(ec == asio::error::operation_aborted);
443-
BOOST_ASSERT(rcs.size() == 1);
444-
BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty);
442+
BOOST_TEST(ec == asio::error::operation_aborted);
443+
BOOST_TEST_REQUIRE(rcs.size() == 1);
444+
BOOST_TEST(rcs[0] == reason_codes::empty);
445445

446446
c.cancel();
447447
}
@@ -451,8 +451,8 @@ void run_cancellation_test(test::msg_exchange broker_side) {
451451
cancel_signal.emit(asio::cancellation_type::total);
452452

453453
ioc.run_for(2s);
454-
BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called);
455-
BOOST_CHECK(broker.received_all_expected());
454+
BOOST_TEST(handlers_called == expected_handlers_called);
455+
BOOST_TEST(broker.received_all_expected());
456456
}
457457

458458
BOOST_FIXTURE_TEST_CASE(cancel_resending_subscribe, shared_test_data) {

test/src/run_tests.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
#include <boost/test/included/unit_test.hpp>
1111

12-
#include <test_common/protocol_logging.hpp>
13-
1412
boost::unit_test::test_suite* init_tests(
1513
int /*argc*/, char* /*argv*/[]
1614
) {
17-
async_mqtt5::test::logging_enabled() = false;
1815
return nullptr;
1916
}
2017

test/unit/connect_op.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void run_unit_test(
6969
).perform(eps, ap);
7070

7171
ioc.run_for(1s);
72-
BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called);
73-
BOOST_CHECK(broker.received_all_expected());
72+
BOOST_TEST(handlers_called == expected_handlers_called);
73+
BOOST_TEST(broker.received_all_expected());
7474
}
7575

7676
void run_unit_test(
@@ -121,7 +121,7 @@ BOOST_FIXTURE_TEST_CASE(fail_to_send_connect, shared_test_data) {
121121
.complete_with(fail, after(2ms));
122122

123123
auto handler = [&](error_code ec) {
124-
BOOST_CHECK(ec == fail);
124+
BOOST_TEST(ec == fail);
125125
};
126126

127127
run_unit_test(std::move(broker_side), std::move(handler));

0 commit comments

Comments
 (0)