Files
boost_beast/test/beast/core/bind_handler.cpp
T

74 lines
1.6 KiB
C++
Raw Normal View History

2017-07-20 08:01:46 -07:00
//
2017-07-24 09:42:36 -07:00
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2017-07-20 08:01:46 -07: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-07-20 08:01:46 -07:00
// Test that header file is self-contained.
2017-07-20 13:40:34 -07:00
#include <boost/beast/core/bind_handler.hpp>
2017-07-20 08:01:46 -07:00
2017-07-20 13:40:34 -07:00
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/beast/unit_test/suite.hpp>
2017-07-19 09:50:16 -07:00
#include <string>
2017-07-20 08:01:46 -07:00
2017-07-20 13:40:34 -07:00
namespace boost {
2017-07-20 08:01:46 -07:00
namespace beast {
2016-05-06 19:14:17 -04:00
class bind_handler_test : public unit_test::suite
2017-07-20 08:01:46 -07:00
{
public:
2017-07-19 09:50:16 -07:00
template<class... Args>
struct handler
{
void
2017-07-19 09:50:16 -07:00
operator()(Args const&...) const
{
}
};
#if 0
// This function should fail to compile
void
failStdBind()
{
2017-07-19 09:50:16 -07:00
std::bind(bind_handler(handler<>{}));
}
#endif
2017-02-06 10:56:37 -05:00
void
callback(int v)
2017-07-20 08:01:46 -07:00
{
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(v == 42);
2017-07-20 08:01:46 -07:00
}
2017-07-19 09:50:16 -07:00
void
testPlaceholders()
{
namespace ph = std::placeholders;
bind_handler(handler<>{})();
bind_handler(handler<int>{}, 1)();
bind_handler(handler<int, std::string>{}, 1, "hello")();
bind_handler(handler<int>{}, ph::_1)(1);
bind_handler(handler<int, std::string>{}, ph::_1, ph::_2)(1, "hello");
}
2017-07-20 08:01:46 -07:00
2017-07-19 09:50:16 -07:00
void
run() override
2017-07-20 08:01:46 -07:00
{
2017-02-06 10:56:37 -05:00
auto f = bind_handler(std::bind(
&bind_handler_test::callback, this,
std::placeholders::_1), 42);
2017-07-20 08:01:46 -07:00
f();
2017-07-19 09:50:16 -07:00
testPlaceholders();
2017-07-20 08:01:46 -07:00
}
};
2017-07-20 13:40:34 -07:00
BOOST_BEAST_DEFINE_TESTSUITE(bind_handler,core,beast);
2017-07-20 08:01:46 -07:00
} // beast
2017-07-20 13:40:34 -07:00
} // boost