mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 21:07:26 +02:00
handler_ptr tests:
fix #932 Ensure handler_ptr cleans up when move-constructing a handler throws an exception. Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
committed by
Vinnie Falco
parent
3edb30b2e8
commit
96e04022c4
@ -1,3 +1,9 @@
|
||||
Version 150:
|
||||
|
||||
* handler_ptr tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Version 149:
|
||||
|
||||
* built-in r-value return values can't be assigned
|
||||
|
@ -24,9 +24,7 @@ public:
|
||||
struct handler
|
||||
{
|
||||
std::unique_ptr<int> ptr;
|
||||
|
||||
void
|
||||
operator()(bool& b) const
|
||||
void operator()(bool& b) const
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
@ -34,8 +32,7 @@ public:
|
||||
|
||||
struct T
|
||||
{
|
||||
explicit
|
||||
T(handler const&)
|
||||
explicit T(handler const&)
|
||||
{
|
||||
}
|
||||
|
||||
@ -44,18 +41,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
testCtorExcept()
|
||||
{
|
||||
struct U
|
||||
{
|
||||
explicit
|
||||
U(handler const&)
|
||||
explicit U(handler const&)
|
||||
{
|
||||
throw std::exception{};
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
handler_ptr<T, handler> p1{handler{}};
|
||||
try
|
||||
{
|
||||
@ -68,13 +63,56 @@ public:
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fail();
|
||||
fail("", __FILE__, __LINE__);
|
||||
}
|
||||
handler_ptr<T, handler> p3{handler{}};
|
||||
}
|
||||
|
||||
void
|
||||
testMoveExcept()
|
||||
{
|
||||
struct throwing_handler
|
||||
{
|
||||
throwing_handler() = default;
|
||||
throwing_handler(throwing_handler&&)
|
||||
{
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
}
|
||||
};
|
||||
struct T
|
||||
{
|
||||
explicit T(throwing_handler const&) noexcept {}
|
||||
};
|
||||
try
|
||||
{
|
||||
throwing_handler h;
|
||||
handler_ptr<T, throwing_handler> p{std::move(h)};
|
||||
fail("", __FILE__, __LINE__);
|
||||
}
|
||||
catch (std::bad_alloc const&)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testInvoke()
|
||||
{
|
||||
handler_ptr<T, handler> p{handler{}};
|
||||
bool b = false;
|
||||
p3.invoke(std::ref(b));
|
||||
p.invoke(std::ref(b));
|
||||
BEAST_EXPECT(b);
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testCtorExcept();
|
||||
testMoveExcept();
|
||||
testInvoke();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,core,handler_ptr);
|
||||
|
Reference in New Issue
Block a user