Skip to content

Commit 9d222ca

Browse files
authored
Merge pull request #822 from redboltz/refine_async_test_checker
Refine ordered call test.
2 parents f161e38 + 5d502c4 commit 9d222ca

32 files changed

+366
-463
lines changed

test/system/checker.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright Takatoshi Kondo 2021
2+
//
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
17
#ifndef MQTT_TEST_CHECKER_HPP
28
#define MQTT_TEST_CHECKER_HPP
39

test/system/ordered_caller.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright Takatoshi Kondo 2021
2+
//
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef MQTT_ORDERED_CALLER_HPP
8+
#define MQTT_ORDERED_CALLER_HPP
9+
10+
#include <vector>
11+
#include <string>
12+
#include <functional>
13+
14+
struct ordered_caller {
15+
template <typename... Funcs>
16+
ordered_caller(std::size_t& index, Funcs&&... funcs)
17+
: index_ {index}, funcs_ { std::forward<Funcs>(funcs)... } {}
18+
bool operator()() {
19+
if (index_ >= funcs_.size()) {
20+
return false;
21+
}
22+
funcs_[index_++]();
23+
return true;
24+
}
25+
private:
26+
std::size_t& index_;
27+
std::vector<std::function<void()>> funcs_;
28+
};
29+
30+
static std::map<std::string, std::size_t> ordered_caller_fileline_to_index;
31+
32+
inline void clear_ordered() {
33+
ordered_caller_fileline_to_index.clear();
34+
}
35+
36+
template <typename... Funcs>
37+
auto make_ordered_caller(std::string file, std::size_t line, Funcs&&... funcs) {
38+
return
39+
ordered_caller{
40+
ordered_caller_fileline_to_index[file + std::to_string(line)],
41+
std::forward<Funcs>(funcs)...
42+
}();
43+
}
44+
45+
#define MQTT_ORDERED(...) \
46+
make_ordered_caller(__FILE__, __LINE__, __VA_ARGS__)
47+
48+
49+
#endif // MQTT_ORDERED_CALLER_HPP

test/system/st_as_buffer_async_pubsub_1.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../common/test_main.hpp"
88
#include "combi_test.hpp"
99
#include "checker.hpp"
10+
#include "ordered_caller.hpp"
1011
#include "../common/global_fixture.hpp"
1112

1213
#include <mqtt/optional.hpp>
@@ -18,6 +19,7 @@ BOOST_AUTO_TEST_SUITE(st_as_buffer_async_pubsub_1)
1819

1920
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
2021
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
22+
clear_ordered();
2123
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
2224
c->set_client_id("cid1");
2325
c->set_clean_session(true);
@@ -233,6 +235,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
233235

234236
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) {
235237
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
238+
clear_ordered();
236239
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
237240
c->set_client_id("cid1");
238241
c->set_clean_session(true);
@@ -460,6 +463,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) {
460463

461464
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) {
462465
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
466+
clear_ordered();
463467
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
464468
c->set_client_id("cid1");
465469
c->set_clean_session(true);
@@ -689,6 +693,7 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) {
689693

690694
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) {
691695
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
696+
clear_ordered();
692697
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
693698
c->set_client_id("cid1");
694699
c->set_clean_session(true);
@@ -903,6 +908,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) {
903908

904909
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) {
905910
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
911+
clear_ordered();
906912
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
907913
c->set_client_id("cid1");
908914
c->set_clean_session(true);
@@ -1128,6 +1134,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) {
11281134

11291135
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) {
11301136
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1137+
clear_ordered();
11311138
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
11321139
c->set_client_id("cid1");
11331140
c->set_clean_session(true);

test/system/st_as_buffer_async_pubsub_2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../common/test_main.hpp"
88
#include "combi_test.hpp"
99
#include "checker.hpp"
10+
#include "ordered_caller.hpp"
1011
#include "../common/global_fixture.hpp"
1112

1213
#include <mqtt/optional.hpp>
@@ -18,6 +19,7 @@ BOOST_AUTO_TEST_SUITE(st_as_buffer_async_pubsub_2)
1819

1920
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) {
2021
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
22+
clear_ordered();
2123
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
2224
c->set_client_id("cid1");
2325
c->set_clean_session(true);
@@ -237,6 +239,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) {
237239

238240
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) {
239241
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
242+
clear_ordered();
240243
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
241244
c->set_client_id("cid1");
242245
c->set_clean_session(true);
@@ -471,6 +474,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) {
471474

472475
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) {
473476
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
477+
clear_ordered();
474478
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
475479
c->set_client_id("cid1");
476480
c->set_clean_session(true);
@@ -707,6 +711,7 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) {
707711

708712
BOOST_AUTO_TEST_CASE( publish_function ) {
709713
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
714+
clear_ordered();
710715
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
711716
c->set_client_id("cid1");
712717
c->set_clean_session(true);
@@ -920,6 +925,7 @@ BOOST_AUTO_TEST_CASE( publish_function ) {
920925

921926
BOOST_AUTO_TEST_CASE( publish_function_buffer ) {
922927
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
928+
clear_ordered();
923929
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
924930
c->set_client_id("cid1");
925931
c->set_clean_session(true);
@@ -1127,6 +1133,7 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) {
11271133

11281134
BOOST_AUTO_TEST_CASE( publish_dup_function ) {
11291135
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1136+
clear_ordered();
11301137
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
11311138
c->set_client_id("cid1");
11321139
c->set_clean_session(true);

test/system/st_as_buffer_pubsub.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../common/test_main.hpp"
88
#include "combi_test.hpp"
99
#include "checker.hpp"
10+
#include "ordered_caller.hpp"
1011
#include "../common/global_fixture.hpp"
1112

1213
#include <mqtt/optional.hpp>
@@ -15,6 +16,7 @@ BOOST_AUTO_TEST_SUITE(st_as_buffer_pubsub)
1516

1617
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
1718
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
19+
clear_ordered();
1820
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
1921
c->set_client_id("cid1");
2022
c->set_clean_session(true);
@@ -195,6 +197,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
195197

196198
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) {
197199
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
200+
clear_ordered();
198201
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
199202
c->set_client_id("cid1");
200203
c->set_clean_session(true);
@@ -384,6 +387,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) {
384387

385388
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) {
386389
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
390+
clear_ordered();
387391
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
388392
c->set_client_id("cid1");
389393
c->set_clean_session(true);
@@ -574,6 +578,7 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) {
574578

575579
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) {
576580
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
581+
clear_ordered();
577582
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
578583
c->set_client_id("cid1");
579584
c->set_clean_session(true);
@@ -753,6 +758,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) {
753758

754759
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) {
755760
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
761+
clear_ordered();
756762
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
757763
c->set_client_id("cid1");
758764
c->set_clean_session(true);
@@ -947,6 +953,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) {
947953

948954
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) {
949955
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
956+
clear_ordered();
950957
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
951958
c->set_client_id("cid1");
952959
c->set_clean_session(true);
@@ -1144,6 +1151,7 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) {
11441151

11451152
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) {
11461153
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1154+
clear_ordered();
11471155
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
11481156
c->set_client_id("cid1");
11491157
c->set_clean_session(true);
@@ -1324,6 +1332,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) {
13241332

13251333
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) {
13261334
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1335+
clear_ordered();
13271336
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
13281337
c->set_client_id("cid1");
13291338
c->set_clean_session(true);
@@ -1518,6 +1527,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) {
15181527

15191528
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) {
15201529
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1530+
clear_ordered();
15211531
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
15221532
c->set_client_id("cid1");
15231533
c->set_clean_session(true);
@@ -1715,6 +1725,7 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) {
17151725

17161726
BOOST_AUTO_TEST_CASE( publish_function ) {
17171727
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1728+
clear_ordered();
17181729
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
17191730
c->set_client_id("cid1");
17201731
c->set_clean_session(true);
@@ -1890,6 +1901,7 @@ BOOST_AUTO_TEST_CASE( publish_function ) {
18901901

18911902
BOOST_AUTO_TEST_CASE( publish_dup_function ) {
18921903
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
1904+
clear_ordered();
18931905
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
18941906
c->set_client_id("cid1");
18951907
c->set_clean_session(true);

test/system/st_as_buffer_sub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../common/test_main.hpp"
88
#include "combi_test.hpp"
99
#include "checker.hpp"
10+
#include "ordered_caller.hpp"
1011
#include "../common/global_fixture.hpp"
1112

1213
#include <mqtt/optional.hpp>
@@ -17,6 +18,7 @@ using namespace std::literals::string_literals;
1718

1819
BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single ) {
1920
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
21+
clear_ordered();
2022
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
2123
c->set_client_id("cid1");
2224
c->set_clean_session(true);
@@ -109,6 +111,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single ) {
109111

110112
BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg ) {
111113
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
114+
clear_ordered();
112115
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
113116
c->set_client_id("cid1");
114117
c->set_clean_session(true);
@@ -213,6 +216,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg ) {
213216

214217
BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec ) {
215218
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
219+
clear_ordered();
216220
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
217221
c->set_client_id("cid1");
218222
c->set_clean_session(true);
@@ -315,6 +319,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec ) {
315319

316320
BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single_async ) {
317321
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
322+
clear_ordered();
318323
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
319324
c->set_client_id("cid1");
320325
c->set_clean_session(true);
@@ -420,6 +425,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single_async ) {
420425

421426
BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg_async ) {
422427
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
428+
clear_ordered();
423429
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
424430
c->set_client_id("cid1");
425431
c->set_clean_session(true);
@@ -540,6 +546,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg_async ) {
540546

541547
BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec_async ) {
542548
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
549+
clear_ordered();
543550
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
544551
c->set_client_id("cid1");
545552
c->set_clean_session(true);

test/system/st_async_pubsub_1.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../common/test_main.hpp"
88
#include "combi_test.hpp"
99
#include "checker.hpp"
10+
#include "ordered_caller.hpp"
1011
#include "../common/global_fixture.hpp"
1112

1213
#include <mqtt/optional.hpp>
@@ -18,6 +19,7 @@ BOOST_AUTO_TEST_SUITE(st_async_pubsub_1)
1819

1920
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
2021
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
22+
clear_ordered();
2123
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
2224
c->set_client_id("cid1");
2325
c->set_clean_session(true);
@@ -202,6 +204,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
202204

203205
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) {
204206
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
207+
clear_ordered();
205208
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
206209
c->set_client_id("cid1");
207210
c->set_clean_session(true);
@@ -402,6 +405,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) {
402405

403406
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) {
404407
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
408+
clear_ordered();
405409
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
406410
c->set_client_id("cid1");
407411
c->set_clean_session(true);
@@ -595,6 +599,7 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) {
595599

596600
BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) {
597601
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
602+
clear_ordered();
598603
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
599604
c->set_client_id("cid1");
600605
c->set_clean_session(true);
@@ -779,6 +784,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) {
779784

780785
BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) {
781786
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
787+
clear_ordered();
782788
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
783789
c->set_client_id("cid1");
784790
c->set_clean_session(true);
@@ -973,6 +979,7 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) {
973979

974980
BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) {
975981
auto test = [](boost::asio::io_context& ioc, auto& c, auto finish, auto& /*b*/) {
982+
clear_ordered();
976983
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
977984
c->set_client_id("cid1");
978985
c->set_clean_session(true);

0 commit comments

Comments
 (0)