1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
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"
17 using namespace boost::container
;
18 using namespace boost::container::pmr
;
22 derived_from_memory_resource d
;
23 memory_resource
&mr
= d
;
26 BOOST_TEST(d
.do_allocate_called
== false);
27 BOOST_TEST(d
.do_allocate_bytes
== 0);
28 BOOST_TEST(d
.do_allocate_alignment
== 0);
31 BOOST_TEST(d
.do_allocate_called
== true);
32 BOOST_TEST(d
.do_allocate_bytes
== 2);
33 BOOST_TEST(d
.do_allocate_alignment
== 4);
36 void test_deallocate()
38 derived_from_memory_resource d
;
39 memory_resource
&mr
= d
;
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);
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);
54 void test_destructor()
57 derived_from_memory_resource d
;
59 BOOST_TEST(derived_from_memory_resource::destructor_called
== false);
61 BOOST_TEST(derived_from_memory_resource::destructor_called
== true);
66 derived_from_memory_resource d
;
67 memory_resource
&mr
= d
;
70 BOOST_TEST(d
.do_is_equal_called
== false);
71 BOOST_TEST(d
.do_is_equal_other
== 0);
74 BOOST_TEST(d
.do_is_equal_called
== true);
75 BOOST_TEST(d
.do_is_equal_other
== &d
);
78 void test_equality_operator()
80 derived_from_memory_resource d
;
81 memory_resource
&mr
= d
;
84 BOOST_TEST(d
.do_is_equal_called
== false);
85 BOOST_TEST(d
.do_is_equal_other
== 0);
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);
92 //unequal addresses are dispatched to is_equal which in turn calls do_is_equal
93 derived_from_memory_resource
d2(1);
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
);
102 void test_inequality_operator()
104 derived_from_memory_resource d
;
105 memory_resource
&mr
= d
;
108 BOOST_TEST(d
.do_is_equal_called
== false);
109 BOOST_TEST(d
.do_is_equal_other
== 0);
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);
116 //unequal addresses are dispatched to is_equal which in turn calls do_is_equal
117 derived_from_memory_resource
d2(1);
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
);
132 test_equality_operator();
133 test_inequality_operator();
134 return ::boost::report_errors();