|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct ConditialThrowOnCopyMock |
|
|
|
|
|
{ |
|
|
|
|
|
explicit ConditialThrowOnCopyMock(Handle h, bool shouldThrow) : m_handle(h), m_shouldThrow(shouldThrow) |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ConditialThrowOnCopyMock(const ConditialThrowOnCopyMock& other) : m_handle(other.m_handle), m_shouldThrow(other.m_shouldThrow) |
|
|
|
|
|
{ |
|
|
|
|
|
if( m_shouldThrow == true ) |
|
|
|
|
|
{ |
|
|
|
|
|
throw std::exception{}; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ConditialThrowOnCopyMock(ConditialThrowOnCopyMock&&) = default; |
|
|
|
|
|
|
|
|
|
|
|
ConditialThrowOnCopyMock& operator=(const ConditialThrowOnCopyMock& other) |
|
|
|
|
|
{ |
|
|
|
|
|
if( &other != this ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_handle = other.m_handle; |
|
|
|
|
|
m_shouldThrow = other.m_shouldThrow; |
|
|
|
|
|
|
|
|
|
|
|
if( m_shouldThrow == true ) |
|
|
|
|
|
{ |
|
|
|
|
|
throw std::exception{}; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ConditialThrowOnCopyMock& operator=(ConditialThrowOnCopyMock&&) = default; |
|
|
|
|
|
|
|
|
|
|
|
Handle m_handle; |
|
|
|
|
|
bool m_shouldThrow; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CallMock m; |
|
|
CallMock m; |
|
|
|
|
|
|
|
|
void deleter(Handle h) |
|
|
void deleter(Handle h) |
|
|
|
|
|
|
|
|
guard.reset(); |
|
|
guard.reset(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: Reset with new value |
|
|
|
|
|
|
|
|
TEST_CASE("reset sets new value and calls deleter on previous", "[UniqueResource]") |
|
|
|
|
|
{ |
|
|
|
|
|
REQUIRE_CALL(m, deleter(3)); |
|
|
|
|
|
REQUIRE_CALL(m, deleter(7)); |
|
|
|
|
|
auto guard = sr::make_unique_resource(Handle{3}, deleter); |
|
|
|
|
|
guard.reset(Handle{7}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
TEST_CASE("release disables deleter", "[UniqueResource]") |
|
|
TEST_CASE("release disables deleter", "[UniqueResource]") |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
auto guard = sr::make_unique_resource(Handle{3}, deleter); |
|
|
auto guard = sr::make_unique_resource(Handle{3}, deleter); |
|
|
CHECK(guard.get() == 3); |
|
|
CHECK(guard.get() == 3); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|