|
22 | 22 |
|
23 | 23 | #include "net_ip/detail/wp_access.hpp"
|
24 | 24 |
|
25 |
| -SCENARIO ( "Weak pointer access utility functions testing", |
26 |
| - "[wp_access]" ) { |
| 25 | +using ne_wp = std::weak_ptr<chops::test::net_entity_mock>; |
| 26 | +using ne_sp = std::shared_ptr<chops::test::net_entity_mock>; |
27 | 27 |
|
28 |
| - using ne_wp = std::weak_ptr<chops::test::net_entity_mock>; |
29 |
| - using ne_sp = std::shared_ptr<chops::test::net_entity_mock>; |
| 28 | +TEST_CASE ( "Weak pointer access utility functions, empty weak ptr", |
| 29 | + "[wp_access]" ) { |
30 | 30 |
|
31 | 31 | ne_wp empty_wp;
|
32 | 32 |
|
33 |
| - GIVEN ("An empty weak pointer") { |
34 |
| - WHEN ("is_started is called, returning bool") { |
35 |
| - THEN ("the return value contains an error") { |
36 |
| - auto r = chops::net::detail::wp_access<bool>(empty_wp, [] (ne_sp nesp) { return nesp->is_started(); } ); |
37 |
| - REQUIRE_FALSE (r); |
38 |
| - INFO("Error code: " << r.error()); |
39 |
| - } |
40 |
| - } |
41 |
| - AND_WHEN ("the wp_access_void function is called") { |
42 |
| - THEN ("the return value contains an error") { |
43 |
| - auto r = chops::net::detail::wp_access_void(empty_wp, [] (ne_sp) { return std::error_code(); } ); |
44 |
| - REQUIRE_FALSE (r); |
45 |
| - INFO("Error code: " << r.error()); |
46 |
| - } |
47 |
| - } |
48 |
| - } // end given |
| 33 | + SECTION ("Check for false when is_started is called on empty weak ptr") { |
| 34 | + auto r = chops::net::detail::wp_access<bool>(empty_wp, [] (ne_sp nesp) { return nesp->is_started(); } ); |
| 35 | + REQUIRE_FALSE (r); |
| 36 | + INFO("Error code: " << r.error()); |
| 37 | + } |
49 | 38 |
|
| 39 | + SECTION ("Check for error code return on wp_access_void") { |
| 40 | + auto r = chops::net::detail::wp_access_void(empty_wp, [] (ne_sp) { return std::error_code(); } ); |
| 41 | + REQUIRE_FALSE (r); |
| 42 | + INFO("Error code: " << r.error()); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +TEST_CASE ("Weak pointer pointing to default constructed net_entity_mock") { |
50 | 47 | auto sp = std::make_shared<chops::test::net_entity_mock>();
|
51 | 48 | ne_wp wp(sp);
|
52 | 49 |
|
53 |
| - GIVEN ("A weak pointer to a default constructed net_entity_mock") { |
54 |
| - WHEN ("is_started is called") { |
55 |
| - THEN ("the return value is false") { |
56 |
| - auto r = chops::net::detail::wp_access<bool>(wp, [] (ne_sp nesp) { return nesp->is_started(); } ); |
57 |
| - REQUIRE (r); |
58 |
| - REQUIRE_FALSE (*r); |
59 |
| - } |
60 |
| - } |
| 50 | + SECTION ("Calling is_started on mock object should return false") { |
| 51 | + auto r = chops::net::detail::wp_access<bool>(wp, [] (ne_sp nesp) { return nesp->is_started(); } ); |
| 52 | + REQUIRE (r); |
| 53 | + REQUIRE_FALSE (*r); |
| 54 | + } |
| 55 | + |
61 | 56 | AND_WHEN ("start is called followed by is_started followed by stop") {
|
62 | 57 | THEN ("all calls succeed") {
|
63 | 58 | auto r1 = chops::net::detail::wp_access_void(wp,
|
|
0 commit comments