]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | ||
8 | // Test that header file is self-contained. | |
9 | #include <beast/core/handler_ptr.hpp> | |
10 | ||
11 | #include <beast/unit_test/suite.hpp> | |
12 | #include <exception> | |
13 | #include <utility> | |
14 | ||
15 | namespace beast { | |
16 | ||
17 | class handler_ptr_test : public beast::unit_test::suite | |
18 | { | |
19 | public: | |
20 | struct handler | |
21 | { | |
22 | handler() = default; | |
23 | handler(handler const&) = default; | |
24 | ||
25 | void | |
26 | operator()(bool& b) const | |
27 | { | |
28 | b = true; | |
29 | } | |
30 | }; | |
31 | ||
32 | struct T | |
33 | { | |
34 | T(handler&) | |
35 | { | |
36 | } | |
37 | ||
38 | ~T() | |
39 | { | |
40 | } | |
41 | }; | |
42 | ||
43 | struct U | |
44 | { | |
45 | U(handler&) | |
46 | { | |
47 | throw std::exception{}; | |
48 | } | |
49 | }; | |
50 | ||
51 | void | |
52 | run() override | |
53 | { | |
54 | handler h; | |
55 | handler_ptr<T, handler> p1{h}; | |
56 | handler_ptr<T, handler> p2{p1}; | |
57 | try | |
58 | { | |
59 | handler_ptr<U, handler> p3{h}; | |
60 | fail(); | |
61 | } | |
62 | catch(std::exception const&) | |
63 | { | |
64 | pass(); | |
65 | } | |
66 | catch(...) | |
67 | { | |
68 | fail(); | |
69 | } | |
70 | handler_ptr<T, handler> p4{std::move(h)}; | |
71 | bool b = false; | |
72 | p4.invoke(std::ref(b)); | |
73 | BEAST_EXPECT(b); | |
74 | } | |
75 | }; | |
76 | ||
77 | BEAST_DEFINE_TESTSUITE(handler_ptr,core,beast); | |
78 | ||
79 | } // beast | |
80 |