forked from boostorg/beast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_ptr.cpp
80 lines (68 loc) · 1.42 KB
/
handler_ptr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// 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)
//
// Test that header file is self-contained.
#include <beast/core/handler_ptr.hpp>
#include <beast/unit_test/suite.hpp>
#include <exception>
#include <utility>
namespace beast {
class handler_ptr_test : public beast::unit_test::suite
{
public:
struct handler
{
handler() = default;
handler(handler const&) = default;
void
operator()(bool& b) const
{
b = true;
}
};
struct T
{
T(handler&)
{
}
~T()
{
}
};
struct U
{
U(handler&)
{
throw std::exception{};
}
};
void
run() override
{
handler h;
handler_ptr<T, handler> p1{h};
handler_ptr<T, handler> p2{p1};
try
{
handler_ptr<U, handler> p3{h};
fail();
}
catch(std::exception const&)
{
pass();
}
catch(...)
{
fail();
}
handler_ptr<T, handler> p4{std::move(h)};
bool b = false;
p4.invoke(std::ref(b));
BEAST_EXPECT(b);
}
};
BEAST_DEFINE_TESTSUITE(handler_ptr,core,beast);
} // beast