]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_test.cpp
c5a571485639e73907e86f91df6895ce09505530
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / allocate_shared_array_test.cpp
1 /*
2 (c) 2012-2015 Glen Joseph Fernandes
3 <glenjofe -at- gmail.com>
4
5 Distributed under the Boost Software
6 License, Version 1.0.
7 http://boost.org/LICENSE_1_0.txt
8 */
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>
13
14 class type {
15 public:
16 static unsigned int instances;
17 explicit type() {
18 instances++;
19 }
20 ~type() {
21 instances--;
22 }
23 private:
24 type(const type&);
25 type& operator=(const type&);
26 };
27
28 unsigned int type::instances = 0;
29
30 int main()
31 {
32 {
33 boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 3);
34 int* a2 = a1.get();
35 BOOST_TEST(a1.use_count() == 1);
36 BOOST_TEST(a2 != 0);
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);
41 }
42 {
43 boost::shared_ptr<int[3]> a1 = boost::allocate_shared<int[3]>(std::allocator<int>());
44 int* a2 = a1.get();
45 BOOST_TEST(a1.use_count() == 1);
46 BOOST_TEST(a2 != 0);
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);
51 }
52 {
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);
60 }
61 {
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);
69 }
70 {
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);
74 BOOST_TEST(a2 != 0);
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);
79 }
80 {
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);
84 BOOST_TEST(a2 != 0);
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);
89 }
90 {
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);
98 }
99 {
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);
107 }
108 {
109 boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
110 type* a2 = a1.get();
111 BOOST_TEST(a1.use_count() == 1);
112 BOOST_TEST(a2 != 0);
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;
116 a1.reset();
117 BOOST_TEST(type::instances == 0);
118 }
119 {
120 boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>());
121 type* a2 = a1.get();
122 BOOST_TEST(a1.use_count() == 1);
123 BOOST_TEST(a2 != 0);
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;
127 a1.reset();
128 BOOST_TEST(type::instances == 0);
129 }
130 {
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);
135 a1.reset();
136 BOOST_TEST(type::instances == 0);
137 }
138 {
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);
143 a1.reset();
144 BOOST_TEST(type::instances == 0);
145 }
146 {
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);
150 BOOST_TEST(a2 != 0);
151 BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
152 BOOST_TEST(type::instances == 3);
153 a1.reset();
154 BOOST_TEST(type::instances == 0);
155 }
156 {
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);
160 BOOST_TEST(a2 != 0);
161 BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
162 BOOST_TEST(type::instances == 3);
163 a1.reset();
164 BOOST_TEST(type::instances == 0);
165 }
166 {
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);
171 a1.reset();
172 BOOST_TEST(type::instances == 0);
173 }
174 {
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);
179 a1.reset();
180 BOOST_TEST(type::instances == 0);
181 }
182 return boost::report_errors();
183 }