2017-01-02 13:29:48 -05:00
|
|
|
//
|
2017-07-24 09:42:36 -07:00
|
|
|
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-01-02 13:29:48 -05:00
|
|
|
//
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
|
//
|
2017-01-02 13:29:48 -05:00
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/handler_ptr.hpp>
|
2017-02-06 10:56:37 -05:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/unit_test/suite.hpp>
|
2017-02-06 10:56:37 -05:00
|
|
|
#include <exception>
|
2017-12-02 16:48:05 +01:00
|
|
|
#include <memory>
|
2017-02-06 10:56:37 -05:00
|
|
|
#include <utility>
|
|
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2017-02-06 10:56:37 -05:00
|
|
|
namespace beast {
|
|
|
|
|
|
|
|
|
|
class handler_ptr_test : public beast::unit_test::suite
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct handler
|
|
|
|
|
{
|
2017-12-02 16:48:05 +01:00
|
|
|
std::unique_ptr<int> ptr;
|
2017-02-06 10:56:37 -05:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
operator()(bool& b) const
|
|
|
|
|
{
|
|
|
|
|
b = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct T
|
|
|
|
|
{
|
2017-12-04 13:02:31 -08:00
|
|
|
explicit
|
|
|
|
|
T(handler const&)
|
2017-02-06 10:56:37 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~T()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct U
|
|
|
|
|
{
|
2017-12-04 13:02:31 -08:00
|
|
|
explicit
|
|
|
|
|
U(handler const&)
|
2017-02-06 10:56:37 -05:00
|
|
|
{
|
|
|
|
|
throw std::exception{};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
run() override
|
|
|
|
|
{
|
2017-12-02 16:48:05 +01:00
|
|
|
handler_ptr<T, handler> p1{handler{}};
|
2017-02-06 10:56:37 -05:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-02 16:48:05 +01:00
|
|
|
handler_ptr<U, handler> p2{handler{}};
|
2017-02-06 10:56:37 -05:00
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
catch(std::exception const&)
|
|
|
|
|
{
|
|
|
|
|
pass();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
|
fail();
|
|
|
|
|
}
|
2017-12-02 16:48:05 +01:00
|
|
|
handler_ptr<T, handler> p3{handler{}};
|
2017-02-06 10:56:37 -05:00
|
|
|
bool b = false;
|
2017-12-02 16:48:05 +01:00
|
|
|
p3.invoke(std::ref(b));
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b);
|
2017-02-06 10:56:37 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-01 17:01:57 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(beast,core,handler_ptr);
|
2017-02-06 10:56:37 -05:00
|
|
|
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|