]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/test/unit/cleanup_test.cpp
update sources to v12.2.3
[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 "cleanup.hpp"
11 #include <boost/core/lightweight_test.hpp>
12 #include <vector>
13
14 struct counted {
15 static int count;
16 static std::vector<int> destroyed;
17 static void reset() {
18 count = 0;
19 destroyed.clear();
20 }
21
22 int value;
23
24 counted(int v) : value(v) {
25 BOOST_TEST(value != -1);
26 ++count;
27 }
28
29 counted(counted const& x) : value(x.value) {
30 BOOST_TEST(value != -1);
31 ++count;
32 }
33
34 ~counted() {
35 BOOST_TEST(value != -1);
36 destroyed.push_back(value);
37 value = -1;
38 BOOST_TEST(count > 0);
39 --count;
40 }
41 };
42
43 int counted::count = 0;
44 std::vector<int> counted::destroyed;
45
46 int main() {
47 counted::reset();
48 {
49 quickbook::cleanup c;
50 }
51 BOOST_TEST(counted::count == 0);
52
53 counted::reset();
54 {
55 quickbook::cleanup c;
56 counted& v1 = c.add(new counted(1));
57 counted& v2 = c.add(new counted(2));
58 BOOST_TEST(v1.value == 1);
59 BOOST_TEST(v2.value == 2);
60 }
61 BOOST_TEST(counted::count == 0);
62 BOOST_TEST(counted::destroyed.size() == 2);
63 BOOST_TEST(counted::destroyed[0] == 2);
64 BOOST_TEST(counted::destroyed[1] == 1);
65
66 counted::reset();
67 {
68 quickbook::cleanup c;
69 int& x = c.add(new int(10));
70 BOOST_TEST(x == 10);
71 }
72
73 return boost::report_errors();
74 }