Skip to content

Commit 4a9af81

Browse files
Convert BDD style to TEST_CASE, std::byte comparisons for Catch2 on Windows
1 parent 207a322 commit 4a9af81

12 files changed

+237
-359
lines changed

test/net_ip/basic_io_interface_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void basic_io_interface_test_compare() {
192192
}
193193

194194
TEST_CASE ( "Basic io interface test, io_handler_mock used for IO handler type",
195-
"[basic_io_interface] [io_handler_mock]" ) {
195+
"[basic_io_interface] [io_handler_mock]" ) {
196196
basic_io_interface_test_default_constructed<chops::test::io_handler_mock>();
197197
basic_io_interface_test_all_start_io<chops::test::io_handler_mock>();
198198
basic_io_interface_test_other_methods<chops::test::io_handler_mock>();

test/net_ip/endpoints_resolver_test.cpp

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,96 +38,90 @@ void make_endpoints_test (bool local, std::string_view host, std::string_view po
3838

3939
chops::net::endpoints_resolver<Protocol> resolver(wk.get_io_context());
4040

41-
GIVEN ("An executor work guard, host, and port strings") {
42-
WHEN ("sync overload of make_endpoints is called") {
43-
THEN ("a sequence of endpoints is returned or an error returned") {
44-
INFO ("-- Host: " << host);
45-
auto results = resolver.make_endpoints(local, host, port);
46-
if (expected_good) {
47-
REQUIRE(results);
48-
INFO ("-- Num endpoints: " << results->size());
49-
REQUIRE_FALSE (results->empty());
50-
}
51-
else {
52-
REQUIRE_FALSE(results);
53-
INFO ("Error code: " << results.error());
54-
}
55-
}
41+
SECTION ("Sync overload, seq of endpoints returned") {
42+
INFO ("-- Host: " << host);
43+
auto results = resolver.make_endpoints(local, host, port);
44+
if (expected_good) {
45+
REQUIRE(results);
46+
INFO ("-- Num endpoints: " << results->size());
47+
REQUIRE_FALSE (results->empty());
48+
}
49+
else {
50+
REQUIRE_FALSE(results);
51+
INFO ("Error code: " << results.error());
5652
}
57-
AND_WHEN ("async overload of make_endpoints is called") {
58-
THEN ("a sequence of endpoints is returned through a function object callback") {
59-
60-
INFO ("-- Host: " << host);
61-
std::promise<prom_ret> res_prom;
62-
auto fut = res_prom.get_future();
63-
resolver.make_endpoints(local, host, port,
64-
[p = std::move(res_prom)] (const std::error_code& err, results_t res) mutable {
65-
p.set_value(prom_ret(err, res));
66-
}
67-
);
68-
auto a = fut.get();
69-
if (expected_good) {
70-
REQUIRE_FALSE(a.first);
71-
INFO ("-- Num endpoints: " << a.second.size());
72-
REQUIRE_FALSE (a.second.empty());
73-
}
74-
else {
75-
REQUIRE(a.first);
76-
INFO ("Error val: " << a.first);
77-
REQUIRE (a.second.empty());
78-
}
53+
}
54+
SECTION ("Async overload, seq endpoints returned") {
55+
INFO ("-- Host: " << host);
56+
std::promise<prom_ret> res_prom;
57+
auto fut = res_prom.get_future();
58+
resolver.make_endpoints(local, host, port,
59+
[p = std::move(res_prom)] (const std::error_code& err, results_t res) mutable {
60+
p.set_value(prom_ret(err, res));
7961
}
62+
);
63+
auto a = fut.get();
64+
if (expected_good) {
65+
REQUIRE_FALSE(a.first);
66+
INFO ("-- Num endpoints: " << a.second.size());
67+
REQUIRE_FALSE (a.second.empty());
68+
}
69+
else {
70+
REQUIRE(a.first);
71+
INFO ("Error val: " << a.first);
72+
REQUIRE (a.second.empty());
8073
}
81-
} // end given
74+
}
8275

8376
wk.reset();
8477

8578
}
8679

87-
SCENARIO ( "Make endpoints remote test, TCP 1",
88-
"[make_endpoints] [tcp]" ) {
80+
TEST_CASE ( "Make endpoints remote test, TCP 1",
81+
"[make_endpoints] [tcp]" ) {
8982

9083
make_endpoints_test<asio::ip::tcp> (false, "www.cnn.com", "80", true);
9184

9285
}
9386

94-
SCENARIO ( "Make endpoints remote test, TCP 2",
95-
"[make_endpoints] [tcp]" ) {
87+
TEST_CASE ( "Make endpoints remote test, TCP 2",
88+
"[make_endpoints] [tcp]" ) {
9689

9790
make_endpoints_test<asio::ip::tcp> (false, "www.seattletimes.com", "80", true);
9891

9992
}
10093

101-
SCENARIO ( "Make endpoints local test, TCP 3",
102-
"[make_endpoints] [tcp]" ) {
94+
TEST_CASE ( "Make endpoints local test, TCP 3",
95+
"[make_endpoints] [tcp]" ) {
10396

10497
make_endpoints_test<asio::ip::tcp> (true, "", "23000", true);
10598

10699
}
107100

108-
SCENARIO ( "Make endpoints remote test, UDP 1",
109-
"[make_endpoints] [udp]" ) {
101+
TEST_CASE ( "Make endpoints remote test, UDP 1",
102+
"[make_endpoints] [udp]" ) {
110103

111104
make_endpoints_test<asio::ip::udp> (false, "www.cnn.com", "80", true);
112105

113106
}
114107

115-
SCENARIO ( "Make endpoints remote test, UDP 2",
116-
"[make_endpoints] [udp]" ) {
108+
TEST_CASE ( "Make endpoints remote test, UDP 2",
109+
"[make_endpoints] [udp]" ) {
117110

118111
make_endpoints_test<asio::ip::udp> (false, "www.seattletimes.com", "80", true);
119112

120113
}
121114

122-
SCENARIO ( "Make endpoints local test, UDP 3",
123-
"[make_endpoints] [udp]" ) {
115+
TEST_CASE ( "Make endpoints local test, UDP 3",
116+
"[make_endpoints] [udp]" ) {
124117

125118
make_endpoints_test<asio::ip::udp> (true, "", "23000", true);
126119

127120
}
128121

129122
/*
130-
SCENARIO ( "Make endpoints remote test, TCP invalid", "[tcp_make_endpoints_invalid]" ) {
123+
TEST_CASE ( "Make endpoints remote test, TCP invalid",
124+
"[tcp_make_endpoints_invalid]" ) {
131125
132126
make_endpoints_test<asio::ip::tcp> (false, "frobozz.blaaaarg", "32555", false);
133127

test/net_ip/net_ip_error_test.cpp

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,16 @@ void will_throw() {
2222
throw ex;
2323
}
2424

25-
SCENARIO ( "Error code and exception test", "[error_code_exception]" ) {
26-
27-
GIVEN ("A function that throws a net_ip exception") {
28-
WHEN ("The function throws") {
29-
THEN ("an exception is present") {
30-
REQUIRE_THROWS (will_throw());
31-
}
32-
}
33-
} // end given
34-
35-
GIVEN ("A function that throws a net_ip exception") {
36-
WHEN ("The function throws") {
37-
THEN ("the exception will contain a custom error message") {
38-
try {
39-
will_throw();
40-
}
41-
catch (const chops::net::net_ip_exception& e) {
42-
INFO ("Error code message: " << e.err.message());
43-
REQUIRE(e.err);
44-
}
45-
}
46-
}
47-
} // end given
25+
TEST_CASE ( "Error code and exception test", "[error_code_exception]" ) {
4826

27+
REQUIRE_THROWS (will_throw());
28+
29+
try {
30+
will_throw();
31+
}
32+
catch (const chops::net::net_ip_exception& e) {
33+
INFO ("Error code message: " << e.err.message());
34+
REQUIRE(e.err);
35+
}
4936
}
5037

test/net_ip/simple_variable_len_msg_frame_test.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,18 @@
2020
#include "net_ip/simple_variable_len_msg_frame.hpp"
2121
#include "shared_test/msg_handling.hpp"
2222

23-
SCENARIO ( "Simple variable length message frame",
24-
"[simple_variable_len_msg_frame]" ) {
23+
TEST_CASE ( "Simple variable length message frame",
24+
"[simple_variable_len_msg_frame]" ) {
2525
using namespace chops::test;
2626

2727
auto ba = chops::make_byte_array(0x02, 0x01); // 513 in big endian
2828

29-
GIVEN ("A two byte buffer that is a variable len msg header") {
30-
WHEN ("the decode variable len msg hdr function is called") {
31-
THEN ("the correct length is returned") {
32-
REQUIRE(decode_variable_len_msg_hdr(ba.data(), 2) == 513);
33-
}
34-
}
35-
AND_WHEN ("a simple variable len msg frame is constructed") {
36-
asio::mutable_buffer buf(ba.data(), ba.size());
37-
chops::net::simple_variable_len_msg_frame mf(decode_variable_len_msg_hdr);
38-
THEN ("the returned length toggles between the decoded length and zero") {
39-
REQUIRE(mf(buf) == 513);
40-
REQUIRE(mf(buf) == 0);
41-
REQUIRE(mf(buf) == 513);
42-
REQUIRE(mf(buf) == 0);
43-
}
44-
}
45-
} // end given
29+
REQUIRE(decode_variable_len_msg_hdr(ba.data(), 2) == 513);
30+
asio::mutable_buffer buf(ba.data(), ba.size());
31+
chops::net::simple_variable_len_msg_frame mf(decode_variable_len_msg_hdr);
32+
REQUIRE(mf(buf) == 513);
33+
REQUIRE(mf(buf) == 0);
34+
REQUIRE(mf(buf) == 513);
35+
REQUIRE(mf(buf) == 0);
4636
}
4737

test/net_ip_component/error_delivery_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
#include "shared_test/mock_classes.hpp"
3434

35-
SCENARIO ( "Testing ostream_error_sink_with_wait_queue function",
36-
"[error_delivery]" ) {
35+
TEST_CASE ( "Testing ostream_error_sink_with_wait_queue function",
36+
"[error_delivery]" ) {
3737

3838
using namespace chops::test;
3939

test/net_ip_component/output_queue_stats_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#include "shared_test/mock_classes.hpp"
2929

30-
SCENARIO ( "Testing accumulate_output_queue_stats for io_output objects",
31-
"[accumulate_output_queue_stats]" ) {
30+
TEST_CASE ( "Testing accumulate_output_queue_stats for io_output objects",
31+
"[accumulate_output_queue_stats]" ) {
3232

3333
using namespace chops::test;
3434
using io_out_mock = chops::net::basic_io_output<io_handler_mock>;
@@ -54,8 +54,8 @@ SCENARIO ( "Testing accumulate_output_queue_stats for io_output objects",
5454

5555
}
5656

57-
SCENARIO ( "Testing accumulate_output_queue_stats for net_entity objects",
58-
"[accumulate_net_entity_output_queue_stats]" ) {
57+
TEST_CASE ( "Testing accumulate_output_queue_stats for net_entity objects",
58+
"[accumulate_net_entity_output_queue_stats]" ) {
5959

6060
// Not much runtime testing, as of yet, in this scenario, mostly compile time, using default
6161
// constructed net_entity objects

0 commit comments

Comments
 (0)