]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/test/unit/cleanup_test.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / tools / quickbook / test / unit / cleanup_test.cpp
1
2 /*=============================================================================
3 Copyright (c) 2017 Daniel James
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9
10 #include <vector>
11 #include <boost/core/lightweight_test.hpp>
12 #include "cleanup.hpp"
13
14 struct counted
15 {
16 static int count;
17 static std::vector<int> destroyed;
18 static void reset()
19 {
20 count = 0;
21 destroyed.clear();
22 }
23
24 int value;
25
26 counted(int v) : value(v)
27 {
28 BOOST_TEST(value != -1);
29 ++count;
30 }
31
32 counted(counted const& x) : value(x.value)
33 {
34 BOOST_TEST(value != -1);
35 ++count;
36 }
37
38 ~counted()
39 {
40 BOOST_TEST(value != -1);
41 destroyed.push_back(value);
42 value = -1;
43 BOOST_TEST(count > 0);
44 --count;
45 }
46 };
47
48 int counted::count = 0;
49 std::vector<int> counted::destroyed;
50
51 int main()
52 {
53 counted::reset();
54 {
55 quickbook::cleanup c;
56 }
57 BOOST_TEST(counted::count == 0);
58
59 counted::reset();
60 {
61 quickbook::cleanup c;
62 counted& v1 = c.add(new counted(1));
63 counted& v2 = c.add(new counted(2));
64 BOOST_TEST(v1.value == 1);
65 BOOST_TEST(v2.value == 2);
66 }
67 BOOST_TEST(counted::count == 0);
68 BOOST_TEST(counted::destroyed.size() == 2);
69 BOOST_TEST(counted::destroyed[0] == 2);
70 BOOST_TEST(counted::destroyed[1] == 1);
71
72 counted::reset();
73 {
74 quickbook::cleanup c;
75 int& x = c.add(new int(10));
76 BOOST_TEST(x == 10);
77 }
78
79 return boost::report_errors();
80 }