blob: daadaf2fb11b191e443ba1173a2783ef74788f99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/utils/scope_exit.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
BOOST_AUTO_TEST_CASE(test_scope_exit)
{
bool flag = false;
{
auto flag_setter = uhd::utils::scope_exit::make([&flag]() { flag = true; });
BOOST_CHECK(!flag);
}
BOOST_CHECK(flag);
}
BOOST_AUTO_TEST_CASE(test_scope_exit_function_object)
{
bool flag = false;
std::function<void(void)> resetter = [&flag]() { flag = true; };
{
auto flag_setter = uhd::utils::scope_exit::make(std::move(resetter));
BOOST_CHECK(!flag);
}
BOOST_CHECK(flag);
}
BOOST_AUTO_TEST_CASE(test_scope_exit_function_named_lambda)
{
bool flag = false;
auto resetter = [&flag]() { flag = true; };
{
// Note: Does not require std::move()
auto flag_setter = uhd::utils::scope_exit::make(resetter);
BOOST_CHECK(!flag);
}
BOOST_CHECK(flag);
}
|