mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-19 13:27:35 +02:00
util/check: stop using lambda for Assert/Assume
This commit is contained in:
parent
7c9fe25c16
commit
2ef47ba6c5
4 changed files with 65 additions and 8 deletions
|
|
@ -78,6 +78,31 @@ BOOST_AUTO_TEST_CASE(util_datadir)
|
|||
BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase());
|
||||
}
|
||||
|
||||
namespace {
|
||||
class NoCopyOrMove
|
||||
{
|
||||
public:
|
||||
int i;
|
||||
explicit NoCopyOrMove(int i) : i{i} { }
|
||||
|
||||
NoCopyOrMove() = delete;
|
||||
NoCopyOrMove(const NoCopyOrMove&) = delete;
|
||||
NoCopyOrMove(NoCopyOrMove&&) = delete;
|
||||
NoCopyOrMove& operator=(const NoCopyOrMove&) = delete;
|
||||
NoCopyOrMove& operator=(NoCopyOrMove&&) = delete;
|
||||
|
||||
operator bool() const { return i != 0; }
|
||||
|
||||
int get_ip1() { return i + 1; }
|
||||
bool test()
|
||||
{
|
||||
// Check that Assume can be used within a lambda and still call methods
|
||||
[&]() { Assume(get_ip1()); }();
|
||||
return Assume(get_ip1() != 5);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_check)
|
||||
{
|
||||
// Check that Assert can forward
|
||||
|
|
@ -89,6 +114,14 @@ BOOST_AUTO_TEST_CASE(util_check)
|
|||
// Check that Assume can be used as unary expression
|
||||
const bool result{Assume(two == 2)};
|
||||
Assert(result);
|
||||
|
||||
// Check that Assert doesn't require copy/move
|
||||
NoCopyOrMove x{9};
|
||||
Assert(x).i += 3;
|
||||
Assert(x).test();
|
||||
|
||||
// Check nested Asserts
|
||||
BOOST_CHECK_EQUAL(Assert((Assert(x).test() ? 3 : 0)), 3);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_criticalsection)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue