]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Howard Hinnant 2009 | |
4 | // (C) Copyright Ion Gaztanaga 2014-2014. | |
5 | // | |
6 | // Distributed under the Boost Software License, Version 1.0. | |
7 | // (See accompanying file LICENSE_1_0.txt or copy at | |
8 | // http://www.boost.org/LICENSE_1_0.txt) | |
9 | // | |
10 | // See http://www.boost.org/libs/move for documentation. | |
11 | // | |
12 | ////////////////////////////////////////////////////////////////////////////// | |
13 | #include <boost/move/utility_core.hpp> | |
14 | #include <boost/move/unique_ptr.hpp> | |
15 | #include <boost/move/detail/type_traits.hpp> | |
16 | #include <boost/static_assert.hpp> | |
17 | #include <boost/core/lightweight_test.hpp> | |
18 | ||
19 | ////////////////////////////////////////////// | |
20 | // | |
21 | // The initial implementation of these tests | |
22 | // was written by Howard Hinnant. | |
23 | // | |
24 | // These test were later refactored grouping | |
25 | // and porting them to Boost.Move. | |
26 | // | |
27 | // Many thanks to Howard for releasing his C++03 | |
28 | // unique_ptr implementation with such detailed | |
29 | // test cases. | |
30 | // | |
31 | ////////////////////////////////////////////// | |
32 | ||
33 | #include "unique_ptr_test_utils_beg.hpp" | |
34 | ||
35 | namespace bml = ::boost::movelib; | |
36 | namespace bmupmu = ::boost::move_upmu; | |
37 | ||
38 | //////////////////////////////// | |
39 | // unique_ptr_pointer_type | |
40 | //////////////////////////////// | |
41 | namespace unique_ptr_pointer_type { | |
42 | ||
43 | struct Deleter | |
44 | { | |
45 | struct pointer {}; | |
46 | }; | |
47 | ||
48 | // Test unique_ptr::pointer type | |
49 | void test() | |
50 | { | |
51 | //Single unique_ptr | |
52 | { | |
53 | typedef bml::unique_ptr<int> P; | |
54 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int*>::value)); | |
55 | } | |
56 | { | |
57 | typedef bml::unique_ptr<int, Deleter> P; | |
58 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value)); | |
59 | } | |
60 | //Unbounded array unique_ptr | |
61 | { | |
62 | typedef bml::unique_ptr<int[]> P; | |
63 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int*>::value)); | |
64 | } | |
65 | { | |
66 | typedef bml::unique_ptr<int[], Deleter> P; | |
67 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value)); | |
68 | } | |
69 | //Bounded array unique_ptr | |
70 | { | |
71 | typedef bml::unique_ptr<int[5]> P; | |
72 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int*>::value)); | |
73 | } | |
74 | { | |
75 | typedef bml::unique_ptr<int[5], Deleter> P; | |
76 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value)); | |
77 | } | |
b32b8144 FG |
78 | //Unbounded array of bounded array unique_ptr |
79 | { | |
80 | typedef int int_5_t [5]; | |
81 | typedef bml::unique_ptr<int_5_t[]> P; | |
82 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int_5_t*>::value)); | |
83 | } | |
84 | { | |
85 | typedef int int_5_t [5]; | |
86 | typedef bml::unique_ptr<int_5_t[], Deleter> P; | |
87 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value)); | |
88 | } | |
7c673cae FG |
89 | } |
90 | ||
91 | } //namespace unique_ptr_pointer_type { | |
92 | ||
93 | //////////////////////////////// | |
94 | // unique_ptr_deleter_type | |
95 | //////////////////////////////// | |
96 | namespace unique_ptr_deleter_type { | |
97 | ||
98 | struct Deleter | |
99 | {}; | |
100 | ||
101 | // Test unique_ptr::deleter type | |
102 | void test() | |
103 | { | |
104 | //Single unique_ptr | |
105 | { | |
106 | typedef bml::unique_ptr<int> P; | |
107 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, bml::default_delete<int> >::value)); | |
108 | } | |
109 | { | |
110 | typedef bml::unique_ptr<int, Deleter> P; | |
111 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, Deleter >::value)); | |
112 | } | |
113 | //Unbounded array unique_ptr | |
114 | { | |
115 | typedef bml::unique_ptr<int[]> P; | |
116 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, bml::default_delete<int[]> >::value)); | |
117 | } | |
118 | { | |
119 | typedef bml::unique_ptr<int[], Deleter> P; | |
120 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, Deleter >::value)); | |
121 | } | |
122 | //Bounded array unique_ptr | |
123 | { | |
124 | typedef bml::unique_ptr<int[2]> P; | |
125 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, bml::default_delete<int[2]> >::value)); | |
126 | } | |
127 | { | |
128 | typedef bml::unique_ptr<int[2], Deleter> P; | |
129 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, Deleter >::value)); | |
130 | } | |
131 | } | |
132 | ||
133 | } //namespace unique_ptr_deleter_type { | |
134 | ||
135 | //////////////////////////////// | |
136 | // unique_ptr_element_type | |
137 | //////////////////////////////// | |
138 | namespace unique_ptr_element_type { | |
139 | ||
140 | // Test unique_ptr::deleter type | |
141 | void test() | |
142 | { | |
143 | //Single unique_ptr | |
144 | { | |
145 | typedef bml::unique_ptr<const int> P; | |
146 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::element_type, const int>::value)); | |
147 | } | |
148 | //Unbounded array unique_ptr | |
149 | { | |
150 | typedef bml::unique_ptr<const int[]> P; | |
151 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::element_type, const int>::value)); | |
152 | } | |
153 | //Bounded array unique_ptr | |
154 | { | |
155 | typedef bml::unique_ptr<const int[2]> P; | |
156 | BOOST_STATIC_ASSERT((bmupmu::is_same<P::element_type, const int>::value)); | |
157 | } | |
158 | } | |
159 | ||
160 | } //namespace unique_ptr_element_type { | |
161 | ||
162 | //////////////////////////////// | |
163 | // unique_ptr_construct_assign_traits | |
164 | //////////////////////////////// | |
165 | ||
166 | namespace unique_ptr_construct_assign_traits { | |
167 | ||
168 | void test() | |
169 | { | |
170 | typedef bml::unique_ptr<int> unique_ptr_t; | |
171 | //Even if BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE is not defined | |
172 | //boost::unique_ptr shall work with boost::movelib traits | |
173 | BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<unique_ptr_t>::value)); | |
174 | //Even if BOOST_MOVE_TT_CXX11_IS_COPY_ASSIGNABLE is not defined | |
175 | //boost::unique_ptr shall work with boost::movelib traits | |
176 | BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<unique_ptr_t>::value)); | |
177 | //Important traits for containers like boost::vector | |
178 | BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<unique_ptr_t>::value)); | |
179 | BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<unique_ptr_t>::value)); | |
180 | } | |
181 | ||
182 | } //namespace unique_ptr_construct_assign_traits { | |
183 | ||
184 | //////////////////////////////// | |
185 | // main | |
186 | //////////////////////////////// | |
187 | ||
188 | int main() | |
189 | { | |
190 | //General | |
191 | unique_ptr_pointer_type::test(); | |
192 | unique_ptr_deleter_type::test(); | |
193 | unique_ptr_element_type::test(); | |
194 | unique_ptr_construct_assign_traits::test(); | |
195 | ||
196 | //Test results | |
197 | return boost::report_errors(); | |
198 | } | |
199 | ||
200 | #include "unique_ptr_test_utils_end.hpp" |