]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_test.cpp
c5a571485639e73907e86f91df6895ce09505530
2 (c) 2012-2015 Glen Joseph Fernandes
3 <glenjofe -at- gmail.com>
5 Distributed under the Boost Software
7 http://boost.org/LICENSE_1_0.txt
9 #include <boost/core/lightweight_test.hpp>
10 #include <boost/smart_ptr/make_shared.hpp>
11 #include <boost/smart_ptr/weak_ptr.hpp>
12 #include <boost/type_traits/alignment_of.hpp>
16 static unsigned int instances
;
25 type
& operator=(const type
&);
28 unsigned int type::instances
= 0;
33 boost::shared_ptr
<int[]> a1
= boost::allocate_shared
<int[]>(std::allocator
<int>(), 3);
35 BOOST_TEST(a1
.use_count() == 1);
37 BOOST_TEST(size_t(a2
) % boost::alignment_of
<int>::value
== 0);
38 BOOST_TEST(a1
[0] == 0);
39 BOOST_TEST(a1
[1] == 0);
40 BOOST_TEST(a1
[2] == 0);
43 boost::shared_ptr
<int[3]> a1
= boost::allocate_shared
<int[3]>(std::allocator
<int>());
45 BOOST_TEST(a1
.use_count() == 1);
47 BOOST_TEST(size_t(a2
) % boost::alignment_of
<int>::value
== 0);
48 BOOST_TEST(a1
[0] == 0);
49 BOOST_TEST(a1
[1] == 0);
50 BOOST_TEST(a1
[2] == 0);
53 boost::shared_ptr
<int[][2]> a1
= boost::allocate_shared
<int[][2]>(std::allocator
<int>(), 2);
54 BOOST_TEST(a1
.get() != 0);
55 BOOST_TEST(a1
.use_count() == 1);
56 BOOST_TEST(a1
[0][0] == 0);
57 BOOST_TEST(a1
[0][1] == 0);
58 BOOST_TEST(a1
[1][0] == 0);
59 BOOST_TEST(a1
[1][1] == 0);
62 boost::shared_ptr
<int[2][2]> a1
= boost::allocate_shared
<int[2][2]>(std::allocator
<int>());
63 BOOST_TEST(a1
.get() != 0);
64 BOOST_TEST(a1
.use_count() == 1);
65 BOOST_TEST(a1
[0][0] == 0);
66 BOOST_TEST(a1
[0][1] == 0);
67 BOOST_TEST(a1
[1][0] == 0);
68 BOOST_TEST(a1
[1][1] == 0);
71 boost::shared_ptr
<const int[]> a1
= boost::allocate_shared
<const int[]>(std::allocator
<int>(), 3);
72 const int* a2
= a1
.get();
73 BOOST_TEST(a1
.use_count() == 1);
75 BOOST_TEST(size_t(a2
) % boost::alignment_of
<int>::value
== 0);
76 BOOST_TEST(a1
[0] == 0);
77 BOOST_TEST(a1
[1] == 0);
78 BOOST_TEST(a1
[2] == 0);
81 boost::shared_ptr
<const int[3]> a1
= boost::allocate_shared
<const int[3]>(std::allocator
<int>());
82 const int* a2
= a1
.get();
83 BOOST_TEST(a1
.use_count() == 1);
85 BOOST_TEST(size_t(a2
) % boost::alignment_of
<int>::value
== 0);
86 BOOST_TEST(a1
[0] == 0);
87 BOOST_TEST(a1
[1] == 0);
88 BOOST_TEST(a1
[2] == 0);
91 boost::shared_ptr
<const int[][2]> a1
= boost::allocate_shared
<const int[][2]>(std::allocator
<int>(), 2);
92 BOOST_TEST(a1
.get() != 0);
93 BOOST_TEST(a1
.use_count() == 1);
94 BOOST_TEST(a1
[0][0] == 0);
95 BOOST_TEST(a1
[0][1] == 0);
96 BOOST_TEST(a1
[1][0] == 0);
97 BOOST_TEST(a1
[1][1] == 0);
100 boost::shared_ptr
<const int[2][2]> a1
= boost::allocate_shared
<const int[2][2]>(std::allocator
<int>());
101 BOOST_TEST(a1
.get() != 0);
102 BOOST_TEST(a1
.use_count() == 1);
103 BOOST_TEST(a1
[0][0] == 0);
104 BOOST_TEST(a1
[0][1] == 0);
105 BOOST_TEST(a1
[1][0] == 0);
106 BOOST_TEST(a1
[1][1] == 0);
109 boost::shared_ptr
<type
[]> a1
= boost::allocate_shared
<type
[]>(std::allocator
<type
>(), 3);
111 BOOST_TEST(a1
.use_count() == 1);
113 BOOST_TEST(size_t(a2
) % boost::alignment_of
<type
>::value
== 0);
114 BOOST_TEST(type::instances
== 3);
115 boost::weak_ptr
<type
[]> w1
= a1
;
117 BOOST_TEST(type::instances
== 0);
120 boost::shared_ptr
<type
[3]> a1
= boost::allocate_shared
<type
[3]>(std::allocator
<type
>());
122 BOOST_TEST(a1
.use_count() == 1);
124 BOOST_TEST(size_t(a2
) % boost::alignment_of
<type
>::value
== 0);
125 BOOST_TEST(type::instances
== 3);
126 boost::weak_ptr
<type
[3]> w1
= a1
;
128 BOOST_TEST(type::instances
== 0);
131 boost::shared_ptr
<type
[][2]> a1
= boost::allocate_shared
<type
[][2]>(std::allocator
<type
>(), 2);
132 BOOST_TEST(a1
.get() != 0);
133 BOOST_TEST(a1
.use_count() == 1);
134 BOOST_TEST(type::instances
== 4);
136 BOOST_TEST(type::instances
== 0);
139 boost::shared_ptr
<type
[2][2]> a1
= boost::allocate_shared
<type
[2][2]>(std::allocator
<type
>());
140 BOOST_TEST(a1
.get() != 0);
141 BOOST_TEST(a1
.use_count() == 1);
142 BOOST_TEST(type::instances
== 4);
144 BOOST_TEST(type::instances
== 0);
147 boost::shared_ptr
<const type
[]> a1
= boost::allocate_shared
<const type
[]>(std::allocator
<type
>(), 3);
148 const type
* a2
= a1
.get();
149 BOOST_TEST(a1
.use_count() == 1);
151 BOOST_TEST(size_t(a2
) % boost::alignment_of
<type
>::value
== 0);
152 BOOST_TEST(type::instances
== 3);
154 BOOST_TEST(type::instances
== 0);
157 boost::shared_ptr
<const type
[3]> a1
= boost::allocate_shared
<const type
[3]>(std::allocator
<type
>());
158 const type
* a2
= a1
.get();
159 BOOST_TEST(a1
.use_count() == 1);
161 BOOST_TEST(size_t(a2
) % boost::alignment_of
<type
>::value
== 0);
162 BOOST_TEST(type::instances
== 3);
164 BOOST_TEST(type::instances
== 0);
167 boost::shared_ptr
<const type
[][2]> a1
= boost::allocate_shared
<const type
[][2]>(std::allocator
<type
>(), 2);
168 BOOST_TEST(a1
.get() != 0);
169 BOOST_TEST(a1
.use_count() == 1);
170 BOOST_TEST(type::instances
== 4);
172 BOOST_TEST(type::instances
== 0);
175 boost::shared_ptr
<const type
[2][2]> a1
= boost::allocate_shared
<const type
[2][2]>(std::allocator
<type
>());
176 BOOST_TEST(a1
.get() != 0);
177 BOOST_TEST(a1
.use_count() == 1);
178 BOOST_TEST(type::instances
== 4);
180 BOOST_TEST(type::instances
== 0);
182 return boost::report_errors();