]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/memory_resource_test.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / container / test / memory_resource_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/container/pmr/memory_resource.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <boost/core/no_exceptions_support.hpp>
13 #include "derived_from_memory_resource.hpp"
14
15 #include <cstdlib>
16
17 using namespace boost::container;
18 using namespace boost::container::pmr;
19
20 void test_allocate()
21 {
22 derived_from_memory_resource d;
23 memory_resource &mr = d;
24
25 d.reset();
26 BOOST_TEST(d.do_allocate_called == false);
27 BOOST_TEST(d.do_allocate_bytes == 0);
28 BOOST_TEST(d.do_allocate_alignment == 0);
29
30 mr.allocate(2, 4);
31 BOOST_TEST(d.do_allocate_called == true);
32 BOOST_TEST(d.do_allocate_bytes == 2);
33 BOOST_TEST(d.do_allocate_alignment == 4);
34 }
35
36 void test_deallocate()
37 {
38 derived_from_memory_resource d;
39 memory_resource &mr = d;
40
41 d.reset();
42 BOOST_TEST(d.do_deallocate_called == false);
43 BOOST_TEST(d.do_deallocate_p == 0);
44 BOOST_TEST(d.do_allocate_bytes == 0);
45 BOOST_TEST(d.do_allocate_alignment == 0);
46
47 mr.deallocate(&d, 2, 4);
48 BOOST_TEST(d.do_deallocate_called == true);
49 BOOST_TEST(d.do_deallocate_p == &d);
50 BOOST_TEST(d.do_deallocate_bytes == 2);
51 BOOST_TEST(d.do_deallocate_alignment == 4);
52 }
53
54 void test_destructor()
55 {
56 {
57 derived_from_memory_resource d;
58 d.reset();
59 BOOST_TEST(derived_from_memory_resource::destructor_called == false);
60 }
61 BOOST_TEST(derived_from_memory_resource::destructor_called == true);
62 }
63
64 void test_is_equal()
65 {
66 derived_from_memory_resource d;
67 memory_resource &mr = d;
68
69 d.reset();
70 BOOST_TEST(d.do_is_equal_called == false);
71 BOOST_TEST(d.do_is_equal_other == 0);
72
73 mr.is_equal(d);
74 BOOST_TEST(d.do_is_equal_called == true);
75 BOOST_TEST(d.do_is_equal_other == &d);
76 }
77
78 void test_equality_operator()
79 {
80 derived_from_memory_resource d;
81 memory_resource &mr = d;
82
83 d.reset();
84 BOOST_TEST(d.do_is_equal_called == false);
85 BOOST_TEST(d.do_is_equal_other == 0);
86
87 //equal addresses are shorcircuited
88 BOOST_TEST((mr == mr) == true);
89 BOOST_TEST(d.do_is_equal_called == false);
90 BOOST_TEST(d.do_is_equal_other == 0);
91
92 //unequal addresses are dispatched to is_equal which in turn calls do_is_equal
93 derived_from_memory_resource d2(1);
94 d.reset();
95 d2.reset();
96 memory_resource &mr2 = d2;
97 BOOST_TEST((mr == mr2) == false);
98 BOOST_TEST(d.do_is_equal_called == true);
99 BOOST_TEST(d.do_is_equal_other == &d2);
100 }
101
102 void test_inequality_operator()
103 {
104 derived_from_memory_resource d;
105 memory_resource &mr = d;
106
107 d.reset();
108 BOOST_TEST(d.do_is_equal_called == false);
109 BOOST_TEST(d.do_is_equal_other == 0);
110
111 //equal addresses are shorcircuited
112 BOOST_TEST((mr != mr) == false);
113 BOOST_TEST(d.do_is_equal_called == false);
114 BOOST_TEST(d.do_is_equal_other == 0);
115
116 //unequal addresses are dispatched to is_equal which in turn calls do_is_equal
117 derived_from_memory_resource d2(1);
118 d.reset();
119 d2.reset();
120 memory_resource &mr2 = d2;
121 BOOST_TEST((mr != mr2) == true);
122 BOOST_TEST(d.do_is_equal_called == true);
123 BOOST_TEST(d.do_is_equal_other == &d2);
124 }
125
126 int main()
127 {
128 test_destructor();
129 test_allocate();
130 test_deallocate();
131 test_is_equal();
132 test_equality_operator();
133 test_inequality_operator();
134 return ::boost::report_errors();
135 }