Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_scoped_exit.cpp
Go to the documentation of this file.
1#include <fc/scoped_exit.hpp>
2
3#define BOOST_TEST_MODULE scoped_exit
4#include <boost/test/included/unit_test.hpp>
5
6using namespace fc;
7
8BOOST_AUTO_TEST_SUITE(scoped_exit_test_suite)
9
10BOOST_AUTO_TEST_CASE(scoped_exit_test)
11{
12 bool result = false;
13 {
14 auto g1 = make_scoped_exit([&]{ result = true; });
15 BOOST_TEST(result == false);
16 }
17 BOOST_TEST(result == true);
18}
19
21 bool result = false;
22 {
23 auto g1 = make_scoped_exit([&]{ result = true; });
24 BOOST_TEST(result == false);
25 g1.cancel();
26 }
27 BOOST_TEST(result == false);
28}
29
31 bool result = false;
32 {
33 auto g1 = make_scoped_exit([&]{ result = true; });
34 BOOST_TEST(result == false);
35 {
36 auto g2 = std::move(g1);
37 BOOST_TEST(result == false);
38 }
39 BOOST_TEST(result == true);
40 result = false;
41 }
42 BOOST_TEST(result == false);
43}
44
45struct move_only {
46 move_only() = default;
47 move_only(move_only&&) = default;
48 void operator()() {}
49};
50
51BOOST_AUTO_TEST_CASE(test_forward) {
52 auto g = make_scoped_exit(move_only{});
53 auto g2 = std::move(g);
54}
55
56BOOST_AUTO_TEST_SUITE_END()
namespace sysio::chain
Definition authority.cpp:3
scoped_exit< Callback > make_scoped_exit(Callback &&c)
move_only()=default
move_only(move_only &&)=default
BOOST_AUTO_TEST_CASE(scoped_exit_test)