|
|
@@ -31,8 +31,32 @@ namespace |
|
|
|
MAKE_MOCK0(deleter, void()); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct ThrowOnCopyMock |
|
|
|
{ |
|
|
|
ThrowOnCopyMock() = default; |
|
|
|
|
|
|
|
ThrowOnCopyMock(const ThrowOnCopyMock&) |
|
|
|
{ |
|
|
|
throw std::exception{}; |
|
|
|
} |
|
|
|
|
|
|
|
MAKE_CONST_MOCK0(deleter, void()); |
|
|
|
|
|
|
|
void operator()() const |
|
|
|
{ |
|
|
|
this->deleter(); |
|
|
|
} |
|
|
|
|
|
|
|
ThrowOnCopyMock& operator=(const ThrowOnCopyMock&) |
|
|
|
{ |
|
|
|
throw std::exception{}; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
CallMock m; |
|
|
|
|
|
|
|
|
|
|
|
void deleter() |
|
|
|
{ |
|
|
|
m.deleter(); |
|
|
@@ -55,6 +79,16 @@ TEST_CASE("deleter lambda called on destruction", "[ScopeGuard]") |
|
|
|
static_cast<void>(guard); |
|
|
|
} |
|
|
|
|
|
|
|
TEST_CASE("deleter called and rethrow on copy exception", "[ScopeGuard]") |
|
|
|
{ |
|
|
|
REQUIRE_THROWS([] { |
|
|
|
const ThrowOnCopyMock noMove; |
|
|
|
REQUIRE_CALL(noMove, deleter()); |
|
|
|
|
|
|
|
sr::scope_guard_t<decltype(noMove)> guard{noMove}; |
|
|
|
}()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST_CASE("deleter is not called if released", "[ScopeGuard]") |
|
|
|
{ |
|
|
|
REQUIRE_CALL(m, deleter()).TIMES(0); |